Sample code for 30+ languages & platforms
Perl

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 chilkat();

$success = 0;

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

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

$numCerts = $certStore->get_NumCertificates();

print "PFX contains " . $numCerts . " certificates" . "\r\n";

$cert = chilkat::CkCert->new();
$i = 0;
while ($i < $numCerts) {
    $certStore->GetCert($i,$cert);

    print $i . ": (Common Name) " . $cert->subjectCN() . "\r\n";
    print $i . ": (Serial Number) " . $cert->serialNumber() . "\r\n";
    print $i . ": (Distinguished Name) " . $cert->subjectDN() . "\r\n";

    $i = $i + 1;
}