Perl Requires Chilkat v10.1.2+
Chilkat2 Perl
Find Certificate by Subject CN (Common Name)
See more Cert Store Examples
Demonstrates how to find a certificate having the specified subject CN.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $certStore = Chilkat2::CertStore->new;
# This opens the Current User certificate store on Windows,
# On MacOS and iOS it opens the default Keychain.
my $readOnly = 0;
my $success = $certStore->OpenCurrentUserStore($readOnly);
if (!$success) {
print $certStore->LastErrorText, "\n";
exit;
}
# Find the certificate having a Subject CN = "Example ABC".
my $json = Chilkat2::JsonObject->new;
$json->UpdateString('CN', 'Example ABC');
my $cert = Chilkat2::Cert->new;
$success = $certStore->FindCert($json, $cert);
if ($success) {
# Show the full distinguished name of the certificate.
print 'Found: ', $cert->SubjectDN, "\n";
} else {
print "Not found.\n";
}