Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

#  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.

set email [new_CkEmail]

CkEmail_put_Subject $email "Confidential"
CkEmail_put_Body $email "Secret contents."

#  Encrypt with a password...
CkEmail_AesEncrypt $email "secret_password"

#  ...then decrypt with the same password to restore the original email.
CkEmail_AesDecrypt $email "secret_password"

puts "Body after decrypt = [CkEmail_body $email]"

delete_CkEmail $email