Sample code for 30+ languages & platforms
Tcl

Load Certificate from Smart Card by Common Name

See more Certificates Examples

This example requires Chilkat v9.5.0.87 or greater. It uses a Windows-only function named LoadFromSmartcard.

This example loads a certificate specified by its subject common name (CN part of the Subject). The LoadFromSmartcard method will examine the connected smart cards and USB tokens and will find and load the certificate having the specified CN.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set cert [new_CkCert]

# If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
CkCert_put_SmartCardPin $cert "12345678"

# To load the certificate specified by CN, pass the string "CN=<subjectCN>".  For example:
set success [CkCert_LoadFromSmartcard $cert "CN=Ch application signature (8c9be8e0-5544-4cd0-9062-290fbff353a7)"]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    puts "Certificate not loaded."
    delete_CkCert $cert
    exit
}

puts "Found: [CkCert_subjectDN $cert] serial=[CkCert_serialNumber $cert]"

# Here's another example:
set cert2 [new_CkCert]

set success [CkCert_LoadFromSmartcard $cert2 "CN=yubikey rsa 1024 authentication"]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert2]
    puts "Certificate not loaded."
    delete_CkCert $cert
    delete_CkCert $cert2
    exit
}

puts "Found: [CkCert_subjectDN $cert2] serial=[CkCert_serialNumber $cert2]"

delete_CkCert $cert
delete_CkCert $cert2