Perl Requires Chilkat v10.1.2+
Chilkat2 Perl
Open Smartcard Certificate Store (or from USB Token)
See more Certificates Examples
Demonstrates how to open the certificate store of the smart card currently in the reader (or the USB token). Iterates over the certs found on the smartcard.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $certStore = Chilkat2::CertStore->new;
# Access the certificates on the smart card or USB token via the Chilkat certificate store class.
# Note: Always pass the empty string to OpenSmartcard.
my $success = $certStore->OpenSmartcard('');
if (!$success) {
print $certStore->LastErrorText, "\n";
exit;
}
print $certStore->LastErrorText, "\n";
# Iterate over certificates on the smartcard.
my $cert = Chilkat2::Cert->new;
my $i = 0;
my $numCerts = $certStore->NumCertificates;
print 'numCerts = ', $numCerts, "\n";
while ($i < $numCerts) {
$certStore->GetCert($i, $cert);
print $cert->SubjectCN, "\n";
print $cert->SerialNumber, "\n";
if ($cert->IsRsa()) {
print "key type is RSA\n";
}
if ($cert->IsEcdsa()) {
print "key type is ECDSA\n";
}
print 'has private key: ', ($cert->HasPrivateKey() ? 1 : 0), "\n";
print "----\n";
$i = $i + 1;
}