Crates.io | rsa-oaep-pss |
lib.rs | rsa-oaep-pss |
version | 1.1.0 |
source | src |
created_at | 2022-10-22 13:29:24.974831 |
updated_at | 2022-11-01 19:34:48.709672 |
description | A pure Rust implementation of the RSA public key cryptosystem |
homepage | |
repository | https://github.com/Hakhenaton/rsa-oaep-pss |
max_upload_size | |
id | 694410 |
size | 104,379 |
A pure Rust implementation of the RSA public key cryptosystem.
The following features are available:
:warning: This crate has not been audited by any peer and is not production-ready: We encourage you to review the code carefully before using it.
Add the following line to your Cargo.toml
dependencies:
[dependencies]
rsa-oaep-pss = "1"
Check out the crates.io page to see what is the latest version of this crate.
let (public_key, private_key) = rsa_oaep_pss::generate_rsa_keys(&mut rng, 2048)
.expect("keys generation error");
let message = b"some secret";
let mut oaep = rsa_oaep_pss::RsaOaep::new(rand::rngs::OsRng, &sha2::Sha256::new());
let ciphertext = oaep
.encrypt(&public_key, message)
.expect("encryption error");
let recovered = oaep
.decrypt(&private_key, &ciphertext)
.expect("decryption error");
assert_eq!(recovered, message);
let message = b"message to sign";
let mut pss = rsa_oaep_pss::RsaPss::new(rand::rngs::OsRng, &sha2::Sha256::new());
let signature = pss.sign(&private_key, message).expect("signature error");
let verification = pss.verify(&public_key, message, &signature);
assert!(verification.is_ok());
use rsa_oaep_pss::{FromPem, ToPem};
let pem_public_key = std::fs::read_to_string("public.pem")?;
let public_key = RsaPublicKey::from_pem(&pem_public_key)?;
let re_exported_pem_public_key = public_key.to_pem()?;
assert_eq!(pem_public_key, re_exported_pem_public_key);
You can also use FromDer
and ToDer
for dealing with raw DER data.
You can run examples contained in the examples
folder by using the following command:
cargo run --example <filename> --release