Rust Requires Chilkat v11.0.0+
Rust
Decrypt an S/MIME email and verify its signature
See more Email Object Examples
Register the recipient’s PFX before opening signed-encrypted.eml. This workflow expects both encryption and a signature, so it checks both layers before reading the message. Cryptographic signature validity is one input to a signer-trust decision.
Chilkat Rust Downloads
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let email = chilkat::Email::new();
if email.add_pfx_source_file("recipient.pfx", "RECIPIENT_PASSWORD").is_err() {
println!("{}", email.last_error_text());
return;
}
if email.load_eml("signed-encrypted.eml").is_err() {
println!("{}", email.last_error_text());
return;
}
if (!email.received_encrypted()) || (!email.decrypted()) {
println!("Expected a successfully decrypted S/MIME envelope.");
return;
}
if (!email.received_signed()) || (!email.signatures_valid()) {
println!("Expected a valid signature inside the envelope.");
return;
}
// This message has one signer. Examine its certificate after verification.
let signer = chilkat::Cert::new();
if email.last_signer_cert(0, &signer).is_err() {
println!("{}", email.last_error_text());
return;
}
println!("Signer certificate: {}", signer.subject_dn());
println!("Recovered subject: {}", email.subject());
println!("Recovered attachments: {}", email.num_attachments());