(Perl) 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.
use chilkat();
$certStore = chilkat::CkCertStore->new();
# This example will search the certs on connected USB tokens and smartcards.
$argNotUsed = "";
$success = $certStore->OpenSmartcard($argNotUsed);
if ($success == 0) {
print $certStore->lastErrorText() . "\r\n";
exit;
}
# Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
$hexSerial = "48FC93B46055948D36A7C98A89D69416";
$json = chilkat::CkJsonObject->new();
$json->UpdateString("serial",$hexSerial);
$cert = chilkat::CkCert->new();
$success = $certStore->FindCert($json,$cert);
if ($success == 1) {
# Show the serial number and subject CN
print "Found: " . $cert->serialNumber() . ", " . $cert->subjectCN() . "\r\n";
}
else {
print "Not found." . "\r\n";
}
|