![]() |
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
(Unicode C++) 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.
#include <CkEmailW.h> #include <CkCertW.h> #include <CkStringBuilderW.h> #include <CkMailManW.h> void ChilkatSample(void) { bool success = false; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkEmailW email; success = email.LoadEml(L"c:/temp/email/unencrypted.eml"); if (success == false) { wprintf(L"%s\n",email.lastErrorText()); return; } // The email content is encrypted using AES with a 256-bit key, operating in GCM mode, which provides authenticated encryption. email.put_Pkcs7CryptAlg(L"aes-gcm"); email.put_Pkcs7KeyLength(256); email.put_OaepPadding(true); email.put_OaepHash(L"sha256"); email.put_OaepMgfHash(L"sha256"); CkCertW cert; success = cert.LoadFromFile(L"c/temps/cert/recipient.cer"); if (success == false) { wprintf(L"%s\n",cert.lastErrorText()); return; } email.put_SendEncrypted(true); email.SetEncryptCert(cert); CkStringBuilderW sbSmime; // 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. CkMailManW mailman; success = mailman.RenderToMimeSb(email,sbSmime); if (success == false) { wprintf(L"%s\n",mailman.lastErrorText()); return; } success = sbSmime.WriteFile(L"c:/temp/encryptedEmail.eml",L"utf-8",false); if (success == false) { wprintf(L"%s\n",mailman.lastErrorText()); return; } wprintf(L"Success!\n"); } |
||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.