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

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $certStore = Chilkat2::CertStore->new;

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

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

my $cert = Chilkat2::Cert->new;
my $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();