Sample code for 30+ languages & platforms
Tcl

Load PEM and List Certificates

Demonstrates how to load a PEM containing certificates and accesses each individual certificate.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set success 0

set pem [new_CkPem]

# Load the .p7b from a file.
set success [CkPem_LoadPemFile $pem "/Users/chilkat/testData/p7b/cacert_mozilla.pem"]
if {$success != 1} then {
    puts [CkPem_lastErrorText $pem]
    delete_CkPem $pem
    exit
}

set numCerts [CkPem_get_NumCerts $pem]
if {$numCerts == 0} then {
    puts "Error: Expected the PEM to contain certificates."
    delete_CkPem $pem
    exit
}

# Access each certificate and show the Subject CN (Common Name)
for {set i 1} {$i <= $numCerts} {incr i} {
    # cert is a CkCert
    set cert [CkPem_GetCert $pem [expr $i - 1]]
    puts "$i: [CkCert_subjectCN $cert]"
    delete_CkCert $cert

}

delete_CkPem $pem