Rust Requires Chilkat v11.0.0+
Rust
Sign an EML using RSA-PSS and SHA-256
See more Email Object Examples
Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.
Chilkat Rust Downloads
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let email = chilkat::Email::new();
if email.load_eml("message.eml").is_err() {
println!("{}", email.last_error_text());
return;
}
let cert = chilkat::Cert::new();
if cert.load_pfx_file("signer.pfx", "PFX_PASSWORD").is_err() {
println!("{}", cert.last_error_text());
return;
}
if email.set_signing_cert(&cert).is_err() {
println!("{}", email.last_error_text());
return;
}
email.set_signing_alg("pss");
email.set_signing_hash_alg("sha256");
email.set_send_signed(true);
let mail = chilkat::MailMan::new();
mail.set_opaque_signing(false);
let rendered = chilkat::BinData::new();
if mail.render_to_mime_bd(&email, &rendered).is_err() {
println!("{}", mail.last_error_text());
return;
}
if rendered.write_file("signed.eml").is_err() {
println!("Failed: rendered.WriteFile.");
return;
}
println!("Saved signed.eml.");