Rust
Rust
Decrypt a .p7m File (using a PFX)
See more Encryption Examples
_LANGUAGE_ sample code showing how to decrypt a .p7m using a .p12 / .pfx certificate w/ private key.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let crypt = chilkat::Crypt2::new();
// Use a digital certificate and private key from a PFX file (.pfx or .p12).
let pfx_path = "myCertAndKey.pfx".to_string();
let pfx_password = "test123".to_string();
if crypt.add_pfx_source_file(&pfx_path, &pfx_password).is_err() {
println!("{}", crypt.last_error_text());
return;
}
// Set the outPath to whatever is appropriate.
// If you are decrypting a PDF, your output might be "out.pdf"...
let in_path = "smime.p7m".to_string();
let out_path = "original.txt".to_string();
// Indicate that we're doing public key decryption (i.e. PKCS7)
crypt.set_crypt_algorithm("pki");
if crypt.ck_decrypt_file(&in_path, &out_path).is_err() {
println!("{}", crypt.last_error_text());
return;
}
println!("Success.");