Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load a PFX from BinData
See more PFX/P12 Examples
Demonstrates Pfx.LoadPfxBd, which loads a PFX / PKCS#12 container from the bytes held in a BinData object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. This is the in-memory equivalent of LoadPfxFile, for when the PKCS#12 data is already available as bytes rather than in a file.
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.BinData,
Chilkat.Pfx;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pfx: TPfx;
bd: TBinData;
bLoaded: Boolean;
password: string;
begin
success := False;
pfx := TPfx.Create;
// The file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// Load the PFX bytes into a BinData.
bd := TBinData.Create;
bLoaded := bd.LoadFile('qa_data/identity.pfx');
if (bLoaded <> True) then
begin
WriteLn('Failed to load the PFX file.');
Exit;
end;
// The PFX password should come from a secure source rather than being hard-coded.
password := 'myPfxPassword';
// Load the PFX / PKCS#12 container from the bytes held in the BinData.
success := pfx.LoadPfxBd(bd,password);
if (success = False) then
begin
WriteLn(pfx.LastErrorText);
Exit;
end;
WriteLn('Loaded ' + pfx.NumCerts + ' certificate(s).');
pfx.Free;
bd.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.