Node.js Requires Chilkat v11.0.0+
Node.js
Encrypt with RSA-OAEP and AES-128-CBC
See more Email Object Examples
Use this profile when the receiver requires AES-128-CBC content encryption and RSA-OAEP with SHA-256. The SHA-256 settings apply to OAEP and its mask generation function. Use the matching decryption example to inspect the result.
Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var email = new chilkat.Email();
success = email.LoadEml("message.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
// Use the recipient's public encryption certificate. Its private key stays with the recipient.
var cert = new chilkat.Cert();
success = cert.LoadFromFile("recipient.cer");
if (success !== true) {
console.log(cert.LastErrorText);
return;
}
success = email.SetEncryptCert(cert);
if (success !== true) {
console.log(email.LastErrorText);
return;
}
email.Pkcs7CryptAlg = "aes";
email.Pkcs7KeyLength = 128;
email.OaepPadding = true;
email.OaepHash = "sha256";
email.OaepMgfHash = "sha256";
email.SendEncrypted = true;
var mail = new chilkat.MailMan();
var rendered = new chilkat.BinData();
success = mail.RenderToMimeBd(email,rendered);
if (success !== true) {
console.log(mail.LastErrorText);
return;
}
success = rendered.WriteFile("oaep-encrypted.eml");
if (success !== true) {
console.log("Failed: rendered.WriteFile.");
return;
}
console.log("Saved oaep-encrypted.eml.");
}
chilkatExample();