Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load PFX (PKCS#12) and List Certificates
See more Certificates Examples
Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.Chilkat Pascal (Lazarus/Delphi) Downloads
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;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
certStore: TCertStore;
pfxPath: string;
pfxPassword: string;
numCerts: Integer;
cert: TCert;
i: Integer;
begin
success := False;
certStore := TCertStore.Create;
pfxPath := '/Users/chilkat/testData/pfx/chilkat_ssl.pfx';
pfxPassword := 'test';
success := certStore.LoadPfxFile(pfxPath,pfxPassword);
if (success <> True) then
begin
WriteLn(certStore.LastErrorText);
Exit;
end;
numCerts := certStore.NumCertificates;
WriteLn('PFX contains ' + numCerts + ' certificates');
cert := TCert.Create;
i := 0;
while i < numCerts do
begin
certStore.GetCert(i,cert);
WriteLn(i + ': (Common Name) ' + cert.SubjectCN);
WriteLn(i + ': (Serial Number) ' + cert.SerialNumber);
WriteLn(i + ': (Distinguished Name) ' + cert.SubjectDN);
i := i + 1;
end;
certStore.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.