Crates.io | rsa_ext |
lib.rs | rsa_ext |
version | 0.1.2 |
source | src |
created_at | 2022-11-30 06:48:57.866863 |
updated_at | 2022-11-30 07:00:49.834909 |
description | Pure Rust RSA implementation |
homepage | |
repository | https://github.com/caisin/RSA |
max_upload_size | |
id | 725955 |
size | 230,454 |
A portable RSA implementation in pure Rust.
⚠️ 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, RsaPublicKey, PaddingScheme};
let mut rng = rand::thread_rng();
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_encrypt(), &data[..]).expect("failed to encrypt");
assert_ne!(&data[..], &enc_data[..]);
// Decrypt
let dec_data = priv_key.decrypt(PaddingScheme::new_pkcs1v15_encrypt(), &enc_data).expect("failed to decrypt");
assert_eq!(&data[..], &dec_data[..]);
Note: If you encounter unusually slow key generation time while using
RsaPrivateKey::new
you can try to compile in release mode or add the following to yourCargo.toml
. Key generation is much faster when building with higher optimization levels, but this will increase the compile time a bit.[profile.debug] opt-level = 3
If you don't want to turn on optimizations for all dependencies, you can only optimize the
num-bigint-dig
dependency. This should give most of the speedups.[profile.dev.package.num-bigint-dig] opt-level = 3
Currently at Phase 1 (v) 🚧
There will be three phases before 1.0
🚢 can be released.
Fuzz testing
Security Audits
All crates in this repository support Rust 1.57 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.