PHP
Chilkat2 PHP
Find Certificate by Subject CN (Common Name)
See more Cert Store Examples
Demonstrates how to find a certificate having the specified subject CN.Note: Requires Chilkat v10.1.2 or later.
Chilkat PHP Downloads
<?php
use Chilkat2\Cert;
use Chilkat2\CertStore;
use Chilkat2\JsonObject;
$certStore = new CertStore();
// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
$readOnly = false;
try {
$certStore->OpenCurrentUserStore($readOnly);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Find the certificate having a Subject CN = "Example ABC".
$json = new JsonObject();
$json->UpdateString('CN', 'Example ABC');
$cert = new Cert();
try {
$certStore->FindCert($json, $cert);
// Show the full distinguished name of the certificate.
echo 'Found: ', $cert->SubjectDN, "\n";
} catch (\Chilkat2\Exception $e) {
echo "Not found.\n";
}