Sample code for 30+ languages & platforms
C

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat C Downloads

C
#include <C_CkCertStore.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStore certStore;
    int numCerts;
    HCkCert cert;
    int i;

    success = FALSE;

    certStore = CkCertStore_Create();

    // On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
    // The argument passed to OpenCurrentUserStore is ignored.
    success = CkCertStore_OpenCurrentUserStore(certStore,FALSE);
    if (success == FALSE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        CkCertStore_Dispose(certStore);
        return;
    }

    numCerts = CkCertStore_getNumCertificates(certStore);
    printf("numCerts = %d\n",numCerts);

    cert = CkCert_Create();
    i = 0;
    while (i < numCerts) {
        CkCertStore_GetCert(certStore,i,cert);
        printf("%s\n",CkCert_subjectDN(cert));
        printf("%s\n",CkCert_subjectCN(cert));
        printf("%s\n",CkCert_serialNumber(cert));
        printf("----\n");
        i = i + 1;
    }

    CkCertStore_CloseCertStore(certStore);


    CkCertStore_Dispose(certStore);
    CkCert_Dispose(cert);

    }