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

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

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

my $pfxPath = '/Users/chilkat/testData/pfx/chilkat_ssl.pfx';
my $pfxPassword = 'test';
my $success = $certStore->LoadPfxFile($pfxPath, $pfxPassword);
if (!$success) {
    print $certStore->LastErrorText, "\n";
    exit;
}

my $numCerts = $certStore->NumCertificates;

print 'PFX contains ', $numCerts, " certificates\n";

my $cert = Chilkat2::Cert->new;
my $i = 0;
while ($i < $numCerts) {
    $certStore->GetCert($i, $cert);

    print $i, ': (Common Name) ', $cert->SubjectCN, "\n";
    print $i, ': (Serial Number) ', $cert->SerialNumber, "\n";
    print $i, ': (Distinguished Name) ', $cert->SubjectDN, "\n";

    $i = $i + 1;
}