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

Load a PFX from an Encoded String

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxEncoded, which decodes text using a named binary encoding (such as base64) and loads the resulting bytes as a PFX / PKCS#12 container.

Background. This is useful when the PKCS#12 data has been transported or stored as printable text, such as base64.

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.Pfx;

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

procedure RunDemo;
var
  success: Boolean;
  pfx: TPfx;
  password: string;
  encodedPfx: string;

begin
  success := False;

  pfx := TPfx.Create;

  //  The PFX password should come from a secure source rather than being hard-coded.
  password := 'myPfxPassword';

  //  Decode the base64 text into PFX / PKCS#12 bytes and load them.  Common encodings include base64
  //  and hex.
  encodedPfx := 'MIIKrAIBAzCCCm...base64-encoded-pfx...';
  success := pfx.LoadPfxEncoded(encodedPfx,'base64',password);
  if (success = False) then
    begin
      WriteLn(pfx.LastErrorText);
      Exit;
    end;
  WriteLn('Loaded ' + pfx.NumCerts + ' certificate(s).');


  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.