Rust
Rust
Add S/MIME Signature using PFX
See more MIME Examples
Add a digital signature to a MIME message using the certificate + private key 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 a PFX file into a certificate object.
let cert = chilkat::Cert::new();
let pfx_filepath = "pfxFiles/something.pfx".to_string();
let pfx_password = "secret".to_string();
if cert.load_pfx_file(&pfx_filepath, &pfx_password).is_err() {
println!("{}", cert.last_error_text());
return;
}
let _ = mime.set_body_from_plain_text("This is the plain-text MIME body.").is_ok();
mime.set_charset("utf-8");
mime.set_encoding("quoted-printable");
// Sign the MIME (adds a PKCS7 detached signature)
if mime.add_detached_signature(&cert).is_err() {
println!("{}", mime.last_error_text());
return;
}
// Save the S/MIME to a file.
if mime.save_mime("/temp/signedMime.txt").is_err() {
println!("{}", mime.last_error_text());
return;
}
println!("success!");