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

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

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

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

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

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

my $cert = Chilkat2::Cert->new;

my $numCerts = $certStore->NumCertificates;
my $i = 0;

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