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

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Chilkat Delphi DLL Downloads

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

begin
success := False;

certStore := CkCertStore_Create();

//  This opens the Current User certificate store on Windows,
//  On MacOS and iOS it opens the default Keychain.
readOnly := False;
success := CkCertStore_OpenCurrentUserStore(certStore,readOnly);
if (success = False) then
  begin
    Memo1.Lines.Add(CkCertStore__lastErrorText(certStore));
    Exit;
  end;

cert := CkCert_Create();

numCerts := CkCertStore_getNumCertificates(certStore);
i := 0;

while (i < numCerts) do
  begin
    //  Load the cert object with the Nth certificate.
    CkCertStore_GetCert(certStore,i,cert);
    Memo1.Lines.Add(IntToStr(i) + ': ' + CkCert__subjectCN(cert));
    i := i + 1;
  end;

CkCertStore_Dispose(certStore);
CkCert_Dispose(cert);