rsa-export

Crates.iorsa-export
lib.rsrsa-export
version0.3.3
sourcesrc
created_at2020-02-25 18:30:55.104986
updated_at2021-03-29 15:12:37.267801
descriptionExport keys generated by the "rsa" crate into the PKCS#1 or PKCS#8 format
homepage
repositoryhttps://gitlab.com/smallglitch/rsa-export
max_upload_size
id212494
size43,858
Aumetra Weisman (aumetra)

documentation

README

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();
Commit count: 30

cargo fmt