Sample code for 30+ languages & platforms
PureBasic

Load Certificate from Smartcard in Reader (or from USB Token)

See more Certificates Examples

Demonstrates how to load the certificate that is on the smartcard currently inserted into the smartcard reader. (Also can load the smartcard on a USB token.)

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCert.pb"

Procedure ChilkatExample()

    success.i = 0

    cert.i = CkCert::ckCreate()
    If cert.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
    CkCert::setCkSmartCardPin(cert, "12345678")

    ; Pass an empty string to allow Chilkat to discover the smart card or USB token automatically.
    success = CkCert::ckLoadFromSmartcard(cert,"")
    If success = 0
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    Debug "Cert loaded from smartcard: " + CkCert::ckSubjectCN(cert)


    CkCert::ckDispose(cert)


    ProcedureReturn
EndProcedure