Sample code for 30+ languages & platforms
PHP 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 PHP Downloads

PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;

$certStore = new CertStore();

$pfxPath = '/Users/chilkat/testData/pfx/chilkat_ssl.pfx';
$pfxPassword = 'test';
try {
    $certStore->LoadPfxFile($pfxPath, $pfxPassword);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$numCerts = $certStore->NumCertificates;

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

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

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

    $i = $i + 1;
}