Sample code for 30+ languages & platforms
Tcl

Add a Decryption Certificate

See more MIME Examples

Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.

AddDecryptCert adds a certificate (with private key access) to the collection Chilkat searches when decrypting. Call it once for each candidate certificate.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. When the intended recipient is not known in advance, several candidate certificates can be added and Chilkat selects the one matching the encrypted message's recipient information.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set mime [new_CkMime]

set success [CkMime_LoadMimeFile $mime "qa_data/encrypted.eml"]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

#  Add a certificate (with access to its private key) to the collection available for decryption.
#  Call it once per candidate certificate; Chilkat picks the one matching the encrypted message.
set pfxPassword "myPfxPassword"
set cert [new_CkCert]

set success [CkCert_LoadPfxFile $cert "qa_data/recipient.pfx" $pfxPassword]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkMime $mime
    delete_CkCert $cert
    exit
}

set success [CkMime_AddDecryptCert $mime $cert]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkCert $cert
    exit
}

set success [CkMime_Decrypt $mime]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkCert $cert
    exit
}

set body [CkMime_getBodyDecoded $mime]
if {[CkMime_get_LastMethodSuccess $mime] == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkCert $cert
    exit
}

puts "$body"

delete_CkMime $mime
delete_CkCert $cert