Rust
Rust
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mime = chilkat::Mime::new();
if mime.load_mime_file("c:/aaworkarea/EmailInBytes.txt").is_err() {
println!("{}", mime.last_error_text());
return;
}
if mime.save_body("c:/aaworkarea/smime.p7m").is_err() {
println!("{}", mime.last_error_text());
return;
}
let crypt = chilkat::Crypt2::new();
if crypt.add_pfx_source_file("c:/aaworkarea/my.pfx", "pfxPassword").is_err() {
println!("{}", crypt.last_error_text());
return;
}
// Indicate the public-key (PKCS7) encryption/decryption should be used:
crypt.set_crypt_algorithm("pki");
let in_path = "c:/aaworkarea/smime.p7m".to_string();
let out_path = "c:/aaworkarea/decrypted.dat".to_string();
if crypt.ck_decrypt_file(&in_path, &out_path).is_err() {
println!("{}", crypt.last_error_text());
return;
}
println!("Success.");