Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
email: HCkEmail;
cert: HCkCert;
mail: HCkMailMan;
rendered: HCkBinData;

begin
success := False;

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

email := CkEmail_Create();
success := CkEmail_LoadEml(email,'message.eml');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkEmail__lastErrorText(email));
    Exit;
  end;
//  Use the recipient's public encryption certificate. Its private key stays with the recipient.
cert := CkCert_Create();
success := CkCert_LoadFromFile(cert,'recipient.cer');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert));
    Exit;
  end;
success := CkEmail_SetEncryptCert(email,cert);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkEmail__lastErrorText(email));
    Exit;
  end;
CkEmail_putPkcs7CryptAlg(email,'aes');
CkEmail_putPkcs7KeyLength(email,128);
CkEmail_putOaepPadding(email,True);
CkEmail_putOaepHash(email,'sha256');
CkEmail_putOaepMgfHash(email,'sha256');
CkEmail_putSendEncrypted(email,True);
mail := CkMailMan_Create();
rendered := CkBinData_Create();
success := CkMailMan_RenderToMimeBd(mail,email,rendered);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mail));
    Exit;
  end;
success := CkBinData_WriteFile(rendered,'oaep-encrypted.eml');
if (success <> True) then
  begin
    Memo1.Lines.Add('Failed: rendered.WriteFile.');
    Exit;
  end;
Memo1.Lines.Add('Saved oaep-encrypted.eml.');

CkEmail_Dispose(email);
CkCert_Dispose(cert);
CkMailMan_Dispose(mail);
CkBinData_Dispose(rendered);