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 <CkCertStore.h>
#include <CkCert.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkCertStore certStore;

    // On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
    // The argument passed to OpenCurrentUserStore is ignored.
    success = certStore.OpenCurrentUserStore(false);
    if (success == false) {
        std::cout << certStore.lastErrorText() << "\r\n";
        return;
    }

    int numCerts = certStore.get_NumCertificates();
    std::cout << "numCerts = " << numCerts << "\r\n";

    CkCert cert;
    int i = 0;
    while (i < numCerts) {
        certStore.GetCert(i,cert);
        std::cout << cert.subjectDN() << "\r\n";
        std::cout << cert.subjectCN() << "\r\n";
        std::cout << cert.serialNumber() << "\r\n";
        std::cout << "----" << "\r\n";
        i = i + 1;
    }

    certStore.CloseCertStore();
    }