Trait rsa::PublicKeyPemEncoding [−][src]
pub trait PublicKeyPemEncoding: PublicKeyEncoding { const PKCS1_HEADER: &'static str; const PKCS8_HEADER: &'static str; fn to_pem_pkcs1(&self) -> Result<String> { ... } fn to_pem_pkcs1_with_config(&self, config: EncodeConfig) -> Result<String> { ... } fn to_pem_pkcs8(&self) -> Result<String> { ... } fn to_pem_pkcs8_with_config(&self, config: EncodeConfig) -> Result<String> { ... } }
Associated Constants
const PKCS1_HEADER: &'static str
const PKCS8_HEADER: &'static str
Provided methods
fn to_pem_pkcs1(&self) -> Result<String>
fn to_pem_pkcs1(&self) -> Result<String>
Converts a Public key into PKCS1
encoded bytes in pem format.
Encodes the key with the header:
-----BEGIN <name> PUBLIC KEY-----
Example
use rsa::{RSAPrivateKey, RSAPublicKey, PublicKeyPemEncoding}; use rand::rngs::OsRng; let mut rng = OsRng; let bits = 2048; let private_key = RSAPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); let public_key = RSAPublicKey::from(&private_key); let _ = public_key.to_pem_pkcs1();
fn to_pem_pkcs1_with_config(&self, config: EncodeConfig) -> Result<String>
fn to_pem_pkcs1_with_config(&self, config: EncodeConfig) -> Result<String>
Converts a Public key into PKCS1
encoded bytes in pem format with encoding config.
Example
use rsa::{RSAPrivateKey, RSAPublicKey, PublicKeyPemEncoding}; use pem::{EncodeConfig, LineEnding}; let _ = public_key.to_pem_pkcs1_with_config(EncodeConfig { line_ending: LineEnding::CRLF, });
fn to_pem_pkcs8(&self) -> Result<String>
fn to_pem_pkcs8(&self) -> Result<String>
Converts a Public key into PKCS8
encoded bytes in pem format.
Encodes the key with the header:
-----BEGIN PUBLIC KEY-----
Example
use rsa::{RSAPrivateKey, RSAPublicKey, PublicKeyPemEncoding}; use rand::rngs::OsRng; let mut rng = OsRng; let bits = 2048; let private_key = RSAPrivateKey::new(&mut rng, bits).expect("failed to generate a key"); let public_key = RSAPublicKey::from(&private_key); let _ = public_key.to_pem_pkcs8();
fn to_pem_pkcs8_with_config(&self, config: EncodeConfig) -> Result<String>
fn to_pem_pkcs8_with_config(&self, config: EncodeConfig) -> Result<String>
Converts a Public key into PKCS8
encoded bytes in pem format with encoding config.
Example
use rsa::{RSAPrivateKey, RSAPublicKey, PublicKeyPemEncoding}; use pem::{EncodeConfig, LineEnding}; let _ = public_key.to_pem_pkcs8_with_config(EncodeConfig { line_ending: LineEnding::CRLF, });