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

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 PHP Downloads

PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;

$certStore = new CertStore();

// Access the certificates on the smart card or USB token via the Chilkat certificate store class.
// Note: Always pass the empty string to OpenSmartcard.

try {
    $certStore->OpenSmartcard('');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo $certStore->LastErrorText, "\n";

// Iterate over certificates on the smartcard.
$cert = new Cert();
$i = 0;
$numCerts = $certStore->NumCertificates;
echo 'numCerts = ', $numCerts, "\n";

while ($i < $numCerts) {
    $certStore->GetCert($i, $cert);
    echo $cert->SubjectCN, "\n";
    echo $cert->SerialNumber, "\n";
    if ($cert->IsRsa()) {
        echo "key type is RSA\n";
    }

    if ($cert->IsEcdsa()) {
        echo "key type is ECDSA\n";
    }

    echo 'has private key: ', ($cert->HasPrivateKey() ? 'true' : 'false'), "\n";
    echo "----\n";
    $i = $i + 1;
}