Need help with RSA?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

145 Stars 41 Forks Other 137 Commits 22 Opened issues


RSA implementation in pure Rust

Services available


Need anything else?

Contributors list

RSA Documentation Build Status minimum rustc 1.44 Project Chat dependency status

A portable RSA implementation in pure Rust.

:warning: WARNING: This crate has been audited by a 3rd party, but a full blog post with the results and the updates made since the audit has not been officially released yet. See #60 for more information.


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(&priv_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

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

Minimum Supported Rust Version (MSRV)

All crates in this repository support Rust 1.44 or higher. In future minimally supported version of Rust can be changed, but it will be done with a minor version bump.


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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.