Delphi DLL
Delphi DLL
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
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Cert, CertStore;
...
procedure TForm1.Button1Click(Sender: TObject);
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.
// ---------------------------------------------------------------------------------------------------------
// The following is true only for Chilkat v10.1.1 and earlier:
// Also, the Chilkat CertStore class can only use MS CNG or CryptoAPI.
// Some smartcard/USB token drivers only support PKCS11 or ScMinidriver.
// You may get better results using Chilkat.Cert.LoadFromSmartcard because
// Cert.LoadFromSmartcard can automatically detect and utilize PKCS11, ScMinidriver, CNG, and CryptoAPI.
// ---------------------------------------------------------------------------------------------------------
// Starting in Chilkat versions after v10.1.1, OpenSmartcard also works with
// Apple Keychain and PKCS11 drivers on Windows, Linux, and MacOS.
// ---------------------------------------------------------------------------------------------------------
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);
end;