Sample code for 30+ languages & platforms
PureBasic

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

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

    ; On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
    ; The argument passed to OpenCurrentUserStore is ignored.
    success = CkCertStore::ckOpenCurrentUserStore(certStore,0)
    If success = 0
        Debug CkCertStore::ckLastErrorText(certStore)
        CkCertStore::ckDispose(certStore)
        ProcedureReturn
    EndIf

    numCerts.i = CkCertStore::ckNumCertificates(certStore)
    Debug "numCerts = " + Str(numCerts)

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

    i.i = 0
    While i < numCerts
        CkCertStore::ckGetCert(certStore,i,cert)
        Debug CkCert::ckSubjectDN(cert)
        Debug CkCert::ckSubjectCN(cert)
        Debug CkCert::ckSerialNumber(cert)
        Debug "----"
        i = i + 1
    Wend

    CkCertStore::ckCloseCertStore(certStore)


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


    ProcedureReturn
EndProcedure