![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Node.js) S/MIME Encrypt .eml without SendingSee more Email Object ExamplesDemonstrates how to encrypt an email using the recipient's digital certificate. This example just encrypts, and does not send the email.
var os = require('os'); if (os.platform() == 'win32') { var chilkat = require('@chilkat/ck-node23-win64'); } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node23-linux-arm'); } else if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node23-linux-arm64'); } else { var chilkat = require('@chilkat/ck-node23-linux-x64'); } } else if (os.platform() == 'darwin') { var chilkat = require('@chilkat/ck-node23-mac-universal'); } function chilkatExample() { var success = false; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. var email = new chilkat.Email(); success = email.LoadEml("c:/temp/email/unencrypted.eml"); if (success == false) { console.log(email.LastErrorText); return; } // The email content is encrypted using AES with a 256-bit key, operating in GCM mode, which provides authenticated encryption. email.Pkcs7CryptAlg = "aes-gcm"; email.Pkcs7KeyLength = 256; email.OaepPadding = true; email.OaepHash = "sha256"; email.OaepMgfHash = "sha256"; var cert = new chilkat.Cert(); success = cert.LoadFromFile("c/temps/cert/recipient.cer"); if (success == false) { console.log(cert.LastErrorText); return; } email.SendEncrypted = true; email.SetEncryptCert(cert); var sbSmime = new chilkat.StringBuilder(); // The mailman object applies the encryption by rendering the email according to the instructions (property settings) provided in the email object. // No email is sent. var mailman = new chilkat.MailMan(); success = mailman.RenderToMimeSb(email,sbSmime); if (success == false) { console.log(mailman.LastErrorText); return; } success = sbSmime.WriteFile("c:/temp/encryptedEmail.eml","utf-8",false); if (success == false) { console.log(mailman.LastErrorText); return; } console.log("Success!"); } chilkatExample(); |
||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.