Expand description
RSA signatures.
New protocols should not use RSA, but it’s still often found in existing protocols. This module implements PKCS#1 signatures (the most common type).
Creating a signature:
use bssl_crypto::{digest, rsa};
// Generating an RSA private key is slow, so this examples parses it from
// PKCS#8 DER.
let private_key = rsa::PrivateKey::from_der_private_key_info(TEST_PKCS8_BYTES).unwrap();
let signed_msg = b"hello world";
let sig = private_key.sign_pkcs1::<digest::Sha256>(signed_msg);To verify a signature, publish your public key:
let public_key_bytes = private_key.as_public().to_der_subject_public_key_info();Then verify the signature from above with it:
let public_key = rsa::PublicKey::from_der_subject_public_key_info(public_key_bytes.as_ref())
.unwrap();
assert!(public_key.verify_pkcs1::<digest::Sha256>(signed_msg, sig.as_slice()).is_ok());
sig[0] ^= 1;
assert!(public_key.verify_pkcs1::<digest::Sha256>(signed_msg, sig.as_slice()).is_err());Structs§
- Private
Key - An RSA private key.
- Public
Key - An RSA public key.
Enums§
- KeySize
- The set of supported RSA key sizes for key generation.