Sample code for 30+ languages & platforms
B4X 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 B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim email As ChilkatEmail
email.Initialize
success = email.LoadEml("message.eml")
If success <> True Then
    Log(email.LastErrorText)
    Return
End If

'  Use the recipient's public encryption certificate. Its private key stays with the recipient.
Dim cert As ChilkatCert
cert.Initialize("cert")
success = cert.LoadFromFile("recipient.cer")
If success <> True Then
    Log(cert.LastErrorText)
    Return
End If

success = email.SetEncryptCert(cert)
If success <> True Then
    Log(email.LastErrorText)
    Return
End If

email.Pkcs7CryptAlg = "aes"
email.Pkcs7KeyLength = 128
email.OaepPadding = True
email.OaepHash = "sha256"
email.OaepMgfHash = "sha256"
email.SendEncrypted = True
Dim mail As ChilkatMailMan
mail.Initialize("mail")
Dim rendered As ChilkatBinData
rendered.Initialize
success = mail.RenderToMimeBd(email, rendered)
If success <> True Then
    Log(mail.LastErrorText)
    Return
End If

success = rendered.WriteFile("oaep-encrypted.eml")
If success <> True Then
    Log("Failed: rendered.WriteFile.")
    Return
End If

Log("Saved oaep-encrypted.eml.")