Sample code for 30+ languages & platforms
Tcl

Add PFX Bytes as a Decryption Source

See more MIME Examples

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

AddPfxSourceBd registers PFX/P12 bytes held in a BinData as a source of certificates and private keys for later decryption.

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. This is the in-memory equivalent of AddPfxSourceFile, for cases where the PKCS #12 data is already loaded into a BinData rather than residing in a file.

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 PFX/P12 bytes (from a BinData) as a source of certificates and private keys for later
#  decryption.  The 1st argument is the BinData and the 2nd is the password (from a secure source).
set bdPfx [new_CkBinData]

set success [CkBinData_LoadFile $bdPfx "qa_data/recipient.pfx"]
if {$success == 0} then {
    puts [CkBinData_lastErrorText $bdPfx]
    delete_CkMime $mime
    delete_CkBinData $bdPfx
    exit
}

set pfxPassword "myPfxPassword"
set success [CkMime_AddPfxSourceBd $mime $bdPfx $pfxPassword]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkBinData $bdPfx
    exit
}

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

puts "Decrypted."

delete_CkMime $mime
delete_CkBinData $bdPfx