rsa 0.3.0

Pure Rust RSA implementation

RSA Documentation Build Status dependency status minimum rustc 1.36

A portable RSA implementation in pure Rust.

:warning: WARNING: This library has not been audited, so please do not use for production code.


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

let mut rng = OsRng;
let bits = 2048;
let priv_key = RSAPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
let pub_key = RSAPublicKey::from(&private_key);

// Encrypt
let data = b"hello world";
let enc_data = pub_key.encrypt(&mut rng, PaddingScheme::new_pkcs1v15(), &data[..]).expect("failed to encrypt");
assert_ne!(&data[..], &enc_data[..]);

// Decrypt
let dec_data = priv_key.decrypt(PaddingScheme::new_pkcs1v15(), &enc_data).expect("failed to decrypt");
assert_eq!(&data[..], &dec_data[..]);


Currently at Phase 1 (v) :construction:.

There will be three phases before 1.0 :ship: can be released.

  1. :construction: Make it work
    • Prime generation :white_check_mark:
    • Key generation :white_check_mark:
    • PKCS1v1.5: Encryption & Decryption :white_check_mark:
    • PKCS1v1.5: Sign & Verify :white_check_mark:
    • PKCS1v1.5 (session key): Encryption & Decryption
    • OAEP: Encryption & Decryption
    • PSS: Sign & Verify
    • Key import & export
  2. :rocket: Make it fast
    • Benchmarks :white_check_mark:
    • compare to other implementations :construction:
    • optimize :construction:
  3. :lock: Make it secure
    • Fuzz testing
    • Security Audits


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.