Function rsa_der::public_key_to_der[][src]

pub fn public_key_to_der(n: &[u8], e: &[u8]) -> Vec<u8>
Expand description

Encodes an RSA public key to DER bytes, as specified by the PKCS#8 format.

The n and e parameters are the big-endian modulus and exponent of the public key, respectively. Simple u8 slices are used to allow usage of this function in conjunction with any crypto library.

Examples

Encoding an RSA public key generated using the rsa crate:

use rand::rngs::OsRng;
use rsa_der::public_key_to_der;
use rsa::{RSAPrivateKey, PublicKey};

let mut rng = OsRng::new().unwrap();
let key = RSAPrivateKey::new(&mut rng, 2048).unwrap();

let der_bytes = public_key_to_der(&key.n().to_bytes_be(), &key.e().to_bytes_be());