Sample code for 30+ languages & platforms
PHP Requires Chilkat v10.1.2+

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;

$certStore = new CertStore();

// On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
// The argument passed to OpenCurrentUserStore is ignored.
try {
    $certStore->OpenCurrentUserStore(false);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$numCerts = $certStore->NumCertificates;
echo 'numCerts = ', $numCerts, "\n";

$cert = new Cert();
$i = 0;
while ($i < $numCerts) {
    $certStore->GetCert($i, $cert);
    echo $cert->SubjectDN, "\n";
    echo $cert->SubjectCN, "\n";
    echo $cert->SerialNumber, "\n";
    echo "----\n";
    $i = $i + 1;
}

$certStore->CloseCertStore();