Sample code for 30+ languages & platforms
PHP Extension

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

$success = false;

$certStore = new CkCertStore();

// On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
// The argument passed to OpenCurrentUserStore is ignored.
$success = $certStore->OpenCurrentUserStore(false);
if ($success == false) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

$numCerts = $certStore->get_NumCertificates();
print 'numCerts = ' . $numCerts . "\n";

$cert = new CkCert();
$i = 0;
while ($i < $numCerts) {
    $certStore->GetCert($i,$cert);
    print $cert->subjectDN() . "\n";
    print $cert->subjectCN() . "\n";
    print $cert->serialNumber() . "\n";
    print '----' . "\n";
    $i = $i + 1;
}

$certStore->CloseCertStore();

?>