Sample code for 30+ languages & platforms
Perl

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

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

# This opens the Current User certificate store on Windows,
# On MacOS and iOS it opens the default Keychain.
$readOnly = 0;
$success = $certStore->OpenCurrentUserStore($readOnly);
if ($success == 0) {
    print $certStore->lastErrorText() . "\r\n";
    exit;
}

$cert = chilkat::CkCert->new();

$numCerts = $certStore->get_NumCertificates();
$i = 0;

while (($i < $numCerts)) {
    # Load the cert object with the Nth certificate.
    $certStore->GetCert($i,$cert);
    print $i . ": " . $cert->subjectCN() . "\r\n";
    $i = $i + 1;
}