C++
C++
Password-Encrypt an Email with AES
See more Email Object Examples
Demonstrates the Chilkat Email.AesEncrypt method, which encrypts the email body, all alternative bodies, all message sub-parts, and attachments using 128-bit AES CBC encryption. This is symmetric, password-based encryption — it does not use certificates or private keys. To decrypt, call AesDecrypt with the same password. Both the sending and receiving applications must use Chilkat and must know the shared password. This example encrypts an email.
Background: This is a Chilkat-specific convenience, distinct from standard S/MIME. Symmetric encryption means one shared secret (the password) both locks and unlocks the message — simple, but it requires a secure way to share that password out-of-band, and only Chilkat-based software can read the result. S/MIME (
SendEncrypted), by contrast, uses public-key certificates and interoperates with standard mail clients. Choose AES password encryption for Chilkat-to-Chilkat exchanges where distributing a shared password is practical.Chilkat C++ Downloads
#include <CkEmail.h>
void ChilkatSample(void)
{
// Demonstrates the AesEncrypt method, which encrypts the email body, all alternative
// bodies, all sub-parts, and attachments using 128-bit AES CBC encryption with a password.
// This is symmetric, password-based encryption -- it does not use certificates. Both the
// sending and receiving applications must use Chilkat and know the same password.
CkEmail email;
email.put_Subject("Confidential");
email.put_Body("This body will be AES-encrypted with a password.");
// Encrypt the entire email using a shared password.
email.AesEncrypt("secret_password");
// The email content is now encrypted. Call AesDecrypt with the same password to restore it.
std::cout << email.getMime() << "\r\n";
}