Sample code for 30+ languages & platforms
Tcl

Serialize a PFX to BinData

See more PFX/P12 Examples

Demonstrates Pfx.ToBd, which serializes the current PFX contents as PKCS#12 data into a BinData object, using the supplied output password.

Background. This is the in-memory equivalent of ToFile, producing the PKCS#12 bytes for further processing or transport.

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.
#  The PFX password should come from a secure source rather than being hard-coded.
set password "myPfxPassword"
set success [CkPfx_LoadPfxFile $pfx "qa_data/identity.pfx" $password]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    exit
}

#  Serialize the PFX contents as PKCS#12 data into a BinData, using the given output password.
set outputPassword "myOutputPassword"
set bd [new_CkBinData]

set success [CkPfx_ToBd $pfx $outputPassword $bd]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    delete_CkBinData $bd
    exit
}

puts "Serialized [CkBinData_get_NumBytes $bd] bytes of PKCS#12 data."

delete_CkPfx $pfx
delete_CkBinData $bd