Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Find a Certificate in the "Other People" Windows Certificate Store

See more Certificates Examples

Demonstrates how to open the "Current User --> Other People" Windows certificate store, and locates a certificate matching an email address.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Cert,
  Chilkat.CertStore,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  certStore: TCertStore;
  readOnly: Boolean;
  jsonE: TJsonObject;
  cert: TCert;

begin
  success := False;

  certStore := TCertStore.Create;

  //  The "AddressBook" is the "Other People" certificate store as shown in certmgr.msc
  readOnly := True;
  success := certStore.OpenWindowsStore('CurrentUser','AddressBook',readOnly);
  if (success <> True) then
    begin
      WriteLn(certStore.LastErrorText);
      Exit;
    end;

  //  Find the certificate for the email address:
  jsonE := TJsonObject.Create;
  jsonE.UpdateString('email','joe@example.com');

  cert := TCert.Create;
  success := certStore.FindCert(jsonE,cert);
  if (success = False) then
    begin
      WriteLn(certStore.LastErrorText);
      Exit;
    end;

  WriteLn('Found certificate: ' + cert.SubjectDN);


  certStore.Free;
  jsonE.Free;
  cert.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.