(PHP ActiveX) Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object. Note: This example requires Chilkat v10.1.2 or greater.
<?php
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.CertStore')
$certStore = new COM("Chilkat.CertStore");
// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
$pfxPassword = 'badssl.com';
$success = $certStore->LoadPfxFile('qa_data/pfx/badssl.com-client.p12',$pfxPassword);
if ($success == 0) {
print $certStore->LastErrorText . "\n";
exit;
}
// Examine each certificate (loaded from the PFX) in this certStore object
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Cert')
$cert = new COM("Chilkat.Cert");
$numCerts = $certStore->NumCertificates;
$i = 0;
while ($i < $numCerts) {
$certStore->GetCert($i,$cert);
print 'hasPrivateKey=' . $cert->HasPrivateKey() . ', ' . $cert->SubjectCN . "\n";
$i = $i + 1;
}
?>
|