Rust
Rust
PKCS7 Decrypt MIME
See more MIME Examples
Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mime = chilkat::Mime::new();
// Load the MIME
if mime.load_mime_file("encryptedMime.txt").is_err() {
println!("{}", mime.last_error_text());
return;
}
// The AddPfxSourceFile and/or AddPfxSourceData
// methods may be called one or more times (one per PFX)
// to add sources from which the MIME component will
// search for certificates and private keys when decrypting.
let pfx_password = "myPassword".to_string();
if mime.add_pfx_source_file("myCertAndPrivateKey.pfx", &pfx_password).is_err() {
println!("{}", mime.last_error_text());
return;
}
// Decrypt...
if mime.decrypt().is_err() {
println!("{}", mime.last_error_text());
return;
}
// Display the decrypted MIME:
println!("{}", mime.get_mime().unwrap_or_default());