You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use rsa::{Pkcs1v15Encrypt,RsaPrivateKey,RsaPublicKey};letmut 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);// Encryptlet data = b"hello world";let enc_data = pub_key.encrypt(&mut rng,Pkcs1v15Encrypt,&data[..]).expect("failed to encrypt");assert_ne!(&data[..],&enc_data[..]);// Decryptlet dec_data = priv_key.decrypt(Pkcs1v15Encrypt,&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 your Cargo.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
Status
Currently at Phase 1 (v) 🚧
There will be three phases before 1.0 🚢 can be released.
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.