Sample code for 30+ languages & platforms
PowerBuilder

Decrypt a Password-Encrypted Email with AES

See more Email Object Examples

Demonstrates the Chilkat Email.AesDecrypt method, which decrypts and restores an email message previously encrypted with AesEncrypt. The password must be the same one used to encrypt. This is Chilkat's password-based email-object decryption — it is not S/MIME certificate-based decryption. This example encrypts an email and then decrypts it to recover the original body.

Background: Symmetric encryption is reversible with the same secret: the identical password that scrambled the message unscrambles it. There is no separate "public" and "private" key as in S/MIME — which makes the scheme simple but means anyone holding the password can both encrypt and decrypt. The round trip shown here (encrypt then decrypt) is a common way to verify the password and confirm the content is faithfully restored.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email

//  Demonstrates the AesDecrypt method, which decrypts and restores an email that was
//  previously encrypted with AesEncrypt.  The password must match the one used to encrypt.
//  This example encrypts an email, then decrypts it to restore the original content.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Confidential"
loo_Email.Body = "Secret contents."

//  Encrypt with a password...
loo_Email.AesEncrypt("secret_password")

//  ...then decrypt with the same password to restore the original email.
loo_Email.AesDecrypt("secret_password")

Write-Debug "Body after decrypt = " + loo_Email.Body


destroy loo_Email