Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v10.1.2+

Open Smartcard Certificate Store (or from USB Token)

See more Certificates Examples

Demonstrates how to open the certificate store of the smart card currently in the reader (or the USB token). Iterates over the certs found on the smartcard.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_CertStore
oleobject loo_Cert
long i
long li_NumCerts

li_Success = 0

loo_CertStore = create oleobject
li_rc = loo_CertStore.ConnectToNewObject("Chilkat.CertStore")
if li_rc < 0 then
    destroy loo_CertStore
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Access the certificates on the smart card or USB token via the Chilkat certificate store class.
//  Note: Always pass the empty string to OpenSmartcard.

li_Success = loo_CertStore.OpenSmartcard("")
if li_Success = 0 then
    Write-Debug loo_CertStore.LastErrorText
    destroy loo_CertStore
    return
end if

Write-Debug loo_CertStore.LastErrorText

//  Iterate over certificates on the smartcard.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

i = 0
li_NumCerts = loo_CertStore.NumCertificates
Write-Debug "numCerts = " + string(li_NumCerts)

do while (i < li_NumCerts)
    loo_CertStore.GetCert(i,loo_Cert)
    Write-Debug loo_Cert.SubjectCN
    Write-Debug loo_Cert.SerialNumber
    if loo_Cert.IsRsa() = 1 then
        Write-Debug "key type is RSA"
    end if

    if loo_Cert.IsEcdsa() = 1 then
        Write-Debug "key type is ECDSA"
    end if

    Write-Debug "has private key: " + string(loo_Cert.HasPrivateKey())
    Write-Debug "----"
    i = i + 1
loop


destroy loo_CertStore
destroy loo_Cert