JavaScript Requires Chilkat v11.0.0+
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var email = new CkEmail();
success = email.LoadEml("message.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
var cert = new CkCert();
success = cert.LoadPfxFile("signer.pfx","PFX_PASSWORD");
if (success !== true) {
console.log(cert.LastErrorText);
return;
}
success = email.SetSigningCert(cert);
if (success !== true) {
console.log(email.LastErrorText);
return;
}
email.SigningAlg = "pss";
email.SigningHashAlg = "sha256";
email.SendSigned = true;
var mail = new CkMailMan();
mail.OpaqueSigning = false;
var rendered = new CkBinData();
success = mail.RenderToMimeBd(email,rendered);
if (success !== true) {
console.log(mail.LastErrorText);
return;
}
success = rendered.WriteFile("signed.eml");
if (success !== true) {
console.log("Failed: rendered.WriteFile.");
return;
}
console.log("Saved signed.eml.");