Sample code for 30+ languages & platforms
Tcl

Find Certificate by Subject CN (Common Name)

See more Cert Store Examples

Demonstrates how to find a certificate having the specified subject CN.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set certStore [new_CkCertStore]

# This opens the Current User certificate store on Windows,
# On MacOS and iOS it opens the default Keychain.
set readOnly 0
set success [CkCertStore_OpenCurrentUserStore $certStore $readOnly]
if {$success == 0} then {
    puts [CkCertStore_lastErrorText $certStore]
    delete_CkCertStore $certStore
    exit
}

# Find the certificate having a Subject CN = "Example ABC".
set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "CN" "Example ABC"

set cert [new_CkCert]

set success [CkCertStore_FindCert $certStore $json $cert]
if {$success == 1} then {
    # Show the full distinguished name of the certificate.
    puts "Found: [CkCert_subjectDN $cert]"
} else {
    puts "Not found."
}


delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert