Sample code for 30+ languages & platforms
Tcl

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set certStore [new_CkCertStore]

# This example will search the certs on connected USB tokens and smartcards.
set argNotUsed ""
set success [CkCertStore_OpenSmartcard $certStore $argNotUsed]
if {$success == 0} then {
    puts [CkCertStore_lastErrorText $certStore]
    delete_CkCertStore $certStore
    exit
}

# Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
set hexSerial "48FC93B46055948D36A7C98A89D69416"
set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "serial" $hexSerial

set cert [new_CkCert]

set success [CkCertStore_FindCert $certStore $json $cert]
if {$success == 1} then {
    # Show the serial number and subject CN
    puts "Found: [CkCert_serialNumber $cert], [CkCert_subjectCN $cert]"
} else {
    puts "Not found."
}


delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert