Sample code for 30+ languages & platforms
Delphi DLL 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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
certStore: HCkCertStore;
cert: HCkCert;
i: Integer;
numCerts: Integer;

begin
success := False;

certStore := CkCertStore_Create();

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

success := CkCertStore_OpenSmartcard(certStore,'');
if (success = False) then
  begin
    Memo1.Lines.Add(CkCertStore__lastErrorText(certStore));
    Exit;
  end;
Memo1.Lines.Add(CkCertStore__lastErrorText(certStore));

//  Iterate over certificates on the smartcard.
cert := CkCert_Create();
i := 0;
numCerts := CkCertStore_getNumCertificates(certStore);
Memo1.Lines.Add('numCerts = ' + IntToStr(numCerts));

while (i < numCerts) do
  begin
    CkCertStore_GetCert(certStore,i,cert);
    Memo1.Lines.Add(CkCert__subjectCN(cert));
    Memo1.Lines.Add(CkCert__serialNumber(cert));
    if (CkCert_IsRsa(cert) = True) then
      begin
        Memo1.Lines.Add('key type is RSA');
      end;
    if (CkCert_IsEcdsa(cert) = True) then
      begin
        Memo1.Lines.Add('key type is ECDSA');
      end;
    Memo1.Lines.Add('has private key: ' + IntToStr(Ord(CkCert_HasPrivateKey(cert))));
    Memo1.Lines.Add('----');
    i := i + 1;
  end;

CkCertStore_Dispose(certStore);
CkCert_Dispose(cert);