Rust Requires Chilkat v11.0.0+
Rust
Sign an email with a key in the Windows Current User certificate store
See more DKIM Examples
Run on Windows as the account that owns the signing certificate. Copy its thumbprint from Current User > Personal and supply it as hexadecimal digits. The thumbprint selects a certificate. The DKIM signature itself uses RSA-SHA256.
The certificate needs an accessible, exportable RSA private key for GetPrivateKey. Publish its matching public key under the selector in DNS. DKIM recipients use that DNS key to verify the message. An X.509 chain is unnecessary for this step.
Chilkat Rust Downloads
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let store = chilkat::CertStore::new();
if store.open_current_user_store(true).is_err() {
println!("{}", store.last_error_text());
return;
}
let search = chilkat::JsonObject::new();
let _ = search.update_string("thumbprint", "YOUR_CERTIFICATE_THUMBPRINT");
let cert = chilkat::Cert::new();
if store.find_cert(&search, &cert).is_err() {
println!("{}", store.last_error_text());
return;
}
if !cert.has_private_key() {
println!("The selected certificate has no accessible private key.");
return;
}
let private_key = chilkat::PrivateKey::new();
if cert.get_private_key(&private_key).is_err() {
println!("{}", cert.last_error_text());
return;
}
let signer = chilkat::Dkim::new();
signer.set_dkim_domain("example.com");
signer.set_dkim_selector("mail2026");
signer.set_dkim_alg("rsa-sha256");
if signer.set_dkim_private_key(&private_key).is_err() {
println!("{}", signer.last_error_text());
return;
}
let message = chilkat::BinData::new();
if message.load_file("message.eml").is_err() {
println!("Could not read message.eml.");
return;
}
if signer.dkim_sign(&message).is_err() {
println!("{}", signer.last_error_text());
return;
}
if message.write_file("signed.eml").is_err() {
println!("Could not write signed.eml.");
return;
}
println!("Saved signed.eml.");