Delphi DLL
Delphi DLL
Find a Certificate by it's SHA-1 Thumbprint
See more Cert Store Examples
Finds a certificate by it's SHA-1 hex thumbprint.Note: This example requires Chilkat v10.1.2 or later.
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, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
certStore: HCkCertStore;
thumbprint: PWideChar;
bReadOnly: Boolean;
json: HCkJsonObject;
cert: HCkCert;
certStorePem: HCkCertStore;
begin
success := False;
certStore := CkCertStore_Create();
thumbprint := '12c1dd8015f3f03f7b1fa619dc24e2493ca8b4b2';
// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
bReadOnly := True;
success := CkCertStore_OpenCurrentUserStore(certStore,bReadOnly);
if (success = False) then
begin
Memo1.Lines.Add(CkCertStore__lastErrorText(certStore));
Exit;
end;
// Find the certificate having a specific SHA1 thumbprint.
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'thumbprint',thumbprint);
cert := CkCert_Create();
success := CkCertStore_FindCert(certStore,json,cert);
if (success = False) then
begin
Memo1.Lines.Add('Failed to find the certificate.');
Exit;
end;
Memo1.Lines.Add('Found: ' + CkCert__subjectCN(cert));
// -------------------------------------------------------------------------------------
// Alternatively, one could load a certificate store object with certs from a PEM file,
// and do the same thing..
certStorePem := CkCertStore_Create();
success := CkCertStore_LoadPemFile(certStorePem,'pemFiles/certificates.pem');
if (success = False) then
begin
Memo1.Lines.Add(CkCertStore__lastErrorText(certStorePem));
Exit;
end;
success := CkCertStore_FindCert(certStore,json,cert);
if (success = False) then
begin
Memo1.Lines.Add('Failed to find the certificate.');
Exit;
end;
Memo1.Lines.Add('Found: ' + CkCert__subjectCN(cert));
CkCertStore_Dispose(certStore);
CkJsonObject_Dispose(json);
CkCert_Dispose(cert);
CkCertStore_Dispose(certStorePem);
end;