(PHP Extension) Find Certificate by Serial Number
Demonstrates how to find a certificate having the specified hexadecimal serial number.
Note: Requires Chilkat v10.1.2 or later.
<?php
include("chilkat.php");
// Use "chilkat_9_5_0.php" for versions of Chilkat < 10.0.0
$certStore = new CkCertStore();
// This example will search the certs on connected USB tokens and smartcards.
$argNotUsed = '';
$success = $certStore->OpenSmartcard($argNotUsed);
if ($success == false) {
print $certStore->lastErrorText() . "\n";
exit;
}
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
$hexSerial = '48FC93B46055948D36A7C98A89D69416';
$json = new CkJsonObject();
$json->UpdateString('serial',$hexSerial);
$cert = new CkCert();
$success = $certStore->FindCert($json,$cert);
if ($success == true) {
// Show the serial number and subject CN
print 'Found: ' . $cert->serialNumber() . ', ' . $cert->subjectCN() . "\n";
}
else {
print 'Not found.' . "\n";
}
?>
|