Sample code for 30+ languages & platforms
PureBasic

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCert.pb"
IncludeFile "CkCertStore.pb"

Procedure ChilkatExample()

    success.i = 0

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

    ; This opens the Current User certificate store on Windows,
    ; On MacOS and iOS it opens the default Keychain.
    readOnly.i = 0
    success = CkCertStore::ckOpenCurrentUserStore(certStore,readOnly)
    If success = 0
        Debug CkCertStore::ckLastErrorText(certStore)
        CkCertStore::ckDispose(certStore)
        ProcedureReturn
    EndIf

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

    numCerts.i = CkCertStore::ckNumCertificates(certStore)
    i.i = 0

    While (i < numCerts)
        ; Load the cert object with the Nth certificate.
        CkCertStore::ckGetCert(certStore,i,cert)
        Debug Str(i) + ": " + CkCert::ckSubjectCN(cert)
        i = i + 1
    Wend


    CkCertStore::ckDispose(certStore)
    CkCert::ckDispose(cert)


    ProcedureReturn
EndProcedure