Sample code for 30+ languages & platforms
Tcl

Load a PFX from BinData

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxBd, which loads a PFX / PKCS#12 container from the bytes held in a BinData object.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. This is the in-memory equivalent of LoadPfxFile, for when the PKCS#12 data is already available as bytes rather than in a file.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set pfx [new_CkPfx]

#  The file path is relative to the application's current working directory.  An absolute path
#  may also be used.  Supply the path appropriate to your own environment.
#  Load the PFX bytes into a BinData.
set bd [new_CkBinData]

set bLoaded [CkBinData_LoadFile $bd "qa_data/identity.pfx"]
if {$bLoaded != 1} then {
    puts "Failed to load the PFX file."
    delete_CkPfx $pfx
    delete_CkBinData $bd
    exit
}

#  The PFX password should come from a secure source rather than being hard-coded.
set password "myPfxPassword"

#  Load the PFX / PKCS#12 container from the bytes held in the BinData.
set success [CkPfx_LoadPfxBd $pfx $bd $password]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    delete_CkBinData $bd
    exit
}

puts "Loaded [CkPfx_get_NumCerts $pfx] certificate(s)."

delete_CkPfx $pfx
delete_CkBinData $bd