Sample code for 30+ languages & platforms
Delphi ActiveX

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

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;
certStore: TChilkatCertStore;
pfxPassword: WideString;
cert: TChilkatCert;
numCerts: Integer;
i: Integer;

begin
success := 0;

certStore := TChilkatCertStore.Create(Self);

// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
pfxPassword := 'badssl.com';
success := certStore.LoadPfxFile('qa_data/pfx/badssl.com-client.p12',pfxPassword);
if (success = 0) then
  begin
    Memo1.Lines.Add(certStore.LastErrorText);
    Exit;
  end;

// Examine each certificate (loaded from the PFX) in this certStore object
cert := TChilkatCert.Create(Self);
numCerts := certStore.NumCertificates;
i := 0;
while i < numCerts do
  begin
    certStore.GetCert(i,cert.ControlInterface);
    Memo1.Lines.Add('hasPrivateKey=' + IntToStr(Ord(cert.HasPrivateKey())) + ', ' + cert.SubjectCN);
    i := i + 1;
  end;
end;