Sample code for 30+ languages & platforms
Delphi ActiveX

Windows Certificate Stores - Find Certificate by Common Name

See more Certificates Examples

Searches the Windows certificate stores for a certificate that matches the specified common name (CN).

Note: This example requires Chilkat v10.0.0 or greater.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
cert: TChilkatCert;

begin
success := 0;

cert := TChilkatCert.Create(Self);
success := cert.LoadByCommonName('Chilkat Software, Inc.');
if (success = 0) then
  begin
    Memo1.Lines.Add(cert.LastErrorText);
    Exit;
  end;

Memo1.Lines.Add(cert.SubjectDN);
Memo1.Lines.Add('Success.');
end;