Sample code for 30+ languages & platforms
Tcl

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set certStore [new_CkCertStore]

# This only loads the contents of the PFX file into the certStore object.
# It is not importing the PFX into the Windows certificate stores.
set pfxPassword "badssl.com"
set success [CkCertStore_LoadPfxFile $certStore "qa_data/pfx/badssl.com-client.p12" $pfxPassword]
if {$success == 0} then {
    puts [CkCertStore_lastErrorText $certStore]
    delete_CkCertStore $certStore
    exit
}

# Examine each certificate (loaded from the PFX) in this certStore object
set cert [new_CkCert]

set numCerts [CkCertStore_get_NumCertificates $certStore]
set i 0
while {$i < $numCerts} {
    CkCertStore_GetCert $certStore $i $cert
    puts "hasPrivateKey=[CkCert_HasPrivateKey $cert], [CkCert_subjectCN $cert]"
    set i [expr $i + 1]
}

delete_CkCertStore $certStore
delete_CkCert $cert