Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created September 17, 2024 14:45
Show Gist options
  • Save jedisct1/7f6fe80fe61867ed4337bb4881b36105 to your computer and use it in GitHub Desktop.
Save jedisct1/7f6fe80fe61867ed4337bb4881b36105 to your computer and use it in GitHub Desktop.
// Cargo.toml:
// [dependencies]
// rsa = "0.9.6"
// rand = "0.8.5"
fn main() -> Result<(), Box<dyn std::error::Error>> {
use rsa::pkcs8::DecodePrivateKey as _;
// Ciphertext
let ciphertext = include_bytes!("signed_message.bin");
// Unencrypted RSA private key in PEM format
let rsa_pem = include_str!("sessionprivatekey.pem");
// Import the RSA private key
let mut rsa_key = rsa::RsaPrivateKey::from_pkcs8_pem(rsa_pem)?;
rsa_key.precompute()?;
// Decrypt the ciphertext
let mut rng = rand::thread_rng();
let plaintext = rsa_key.decrypt_blinded(&mut rng, rsa::Pkcs1v15Encrypt, ciphertext)?;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment