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

Load PFX/P12 from a Base64 Encoded PFX File

See more PFX/P12 Examples

Demonstrates how to call LoadPfxEncoded.

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.BinData,
  Chilkat.Pfx;

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

procedure RunDemo;
var
  success: Boolean;
  bd: TBinData;
  strBase64: string;
  pfx: TPfx;
  password: string;

begin
  success := False;

  bd := TBinData.Create;

  success := bd.LoadFile('qa_data/pfx/cert_test123.pfx');
  if (success <> True) then
    begin
      WriteLn('Failed to load PFX file.');
      Exit;
    end;

  //  Get the bytes contained in the PFX in base64 format:
  strBase64 := bd.GetEncoded('base64');

  //  The base64 looks like this:  "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..."
  WriteLn(strBase64);

  pfx := TPfx.Create;

  //  Load the PFX from the base64 string
  password := 'test123';
  success := pfx.LoadPfxEncoded(strBase64,'base64',password);
  if (success <> True) then
    begin
      WriteLn(pfx.LastErrorText);
      Exit;
    end;

  WriteLn('success');


  bd.Free;
  pfx.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.