#rsa-key #pkcs #export #pem #format #generated #encode

unmaintained rsa-export

Export keys generated by the "rsa" crate into the PKCS#1 or PKCS#8 format

5 unstable releases

0.3.3 Mar 29, 2021
0.3.2 Jan 20, 2021
0.2.1 Nov 25, 2020
0.1.2 Nov 17, 2020
0.1.0 Feb 25, 2020

#19 in #pem

Download history 128/week @ 2024-07-22 205/week @ 2024-07-29 219/week @ 2024-08-05 134/week @ 2024-08-12 219/week @ 2024-08-19 790/week @ 2024-08-26 1169/week @ 2024-09-02 491/week @ 2024-09-09 661/week @ 2024-09-16 1344/week @ 2024-09-23 1144/week @ 2024-09-30 638/week @ 2024-10-07 714/week @ 2024-10-14 762/week @ 2024-10-21 465/week @ 2024-10-28 405/week @ 2024-11-04

2,376 downloads per month
Used in 28 crates (2 directly)

Apache-2.0 OR MIT

17KB
271 lines

DEPRECATED: As of version 0.4, the rsa crate supports exporting keys natively. Please use this over rsa_export, if you can!

rsa_export allows you to export your RSA key, generated via the rsa crate, with PKCS#1 or PKCS#8 encoding

Reference: https://tools.ietf.org/html/rfc3447#appendix-A.1

Note: Multi-prime keys are not supported

The keys can also be exported into the PEM format by enabling the feature pem

Example:

use rsa::RSAPrivateKey;
use rand::rngs::OsRng;
use rsa_export::Encode;

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

let pkcs1_encoded_private = private_key.as_pkcs1().unwrap();
let pkcs1_encoded_public = public_key.as_pkcs1().unwrap();

let pkcs8_encoded_private = private_key.as_pkcs8().unwrap();
let pkcs8_encoded_public = public_key.as_pkcs8().unwrap();

Encode PKCS#1 or PKCS#8 encoded keys into the PEM format (with the pem feature enabled)

use rsa::RSAPrivateKey;
use rand::rngs::OsRng;
use rsa_export::PemEncode;

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

let pkcs1_encoded_private_pem = private_key.as_pkcs1_pem().unwrap();
let pkcs1_encoded_public_pem = public_key.as_pkcs1_pem().unwrap();

let pkcs8_encoded_private_pem = private_key.as_pkcs8_pem().unwrap();
let pkcs8_encoded_public_pem = public_key.as_pkcs8_pem().unwrap();

Dependencies

~10MB
~175K SLoC