Sample code for 30+ languages & platforms
JavaScript Requires Chilkat v11.8.0+

Inspect S/MIME protection when loading an email

See more Email Object Examples

Load a signed or encrypted message and inspect each layer the parser encountered. Register the recipient's certificate and private key first (AddPemSource) for encrypted input. SignaturesValid reports the cryptographic verification result. Applications that rely on signer identity must also validate the certificate and their trust policy.

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.
JavaScript
var success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

var email = new CkEmail();
//  For encrypted input, register the matching certificate and private key (here from a PEM file)
//  before LoadEml:
//  new Pem pem;
//  success = pem.LoadPemFile("recipient.pem","PEM_PASSWORD");
//  success = email.AddPemSource(pem);
success = email.LoadEml("signed.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

console.log("Encryption layer present: " + email.ReceivedEncrypted);
if (email.ReceivedEncrypted == true) {
    console.log("Decrypted: " + email.Decrypted);
}

console.log("Signature layer present: " + email.ReceivedSigned);
if (email.ReceivedSigned == true) {
    console.log("Signature verified: " + email.SignaturesValid);
    if (email.SignaturesValid == true) {
        console.log("Signer: " + email.SignedBy);
    }

}