Sample code for 30+ languages & platforms
Perl

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

$certStore = chilkat::CkCertStore->new();

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

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

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

$certStore->CloseCertStore();