Sample code for 30+ languages & platforms
Perl Requires Chilkat v10.1.2+

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $certStore = Chilkat2::CertStore->new;

# This example will search the certs on connected USB tokens and smartcards.
my $argNotUsed = '';
my $success = $certStore->OpenSmartcard($argNotUsed);
if (!$success) {
    print $certStore->LastErrorText, "\n";
    exit;
}

# Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
my $hexSerial = '48FC93B46055948D36A7C98A89D69416';
my $json = Chilkat2::JsonObject->new;
$json->UpdateString('serial', $hexSerial);

my $cert = Chilkat2::Cert->new;
$success = $certStore->FindCert($json, $cert);
if ($success) {
    # Show the serial number and subject CN
    print 'Found: ', $cert->SerialNumber, ', ', $cert->SubjectCN, "\n";
} else {
    print "Not found.\n";
}