Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load a Public Key from BinData
Demonstrates the Chilkat PublicKey.LoadBd method, which loads a public key from the bytes in a BinData. The only argument is the BinData, which may contain binary DER or any textual representation recognized by LoadFromString.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: When key bytes are already in memory — downloaded, extracted from a container, or pulled from a database — this loads them directly with no temporary file. It applies the same content inspection as the string and file loaders, so it accepts both binary DER and any recognized text form. It is the in-memory counterpart to
LoadFromFile.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.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
pubKey: TPublicKey;
begin
success := False;
// Demonstrates the PublicKey.LoadBd method, which loads a public key from the bytes in a BinData.
// The only argument is the BinData, which may contain binary DER or any textual representation
// recognized by LoadFromString.
bd := TBinData.Create;
success := bd.LoadFile('qa_data/public.der');
if (success = False) then
begin
WriteLn(bd.LastErrorText);
Exit;
end;
pubKey := TPublicKey.Create;
success := pubKey.LoadBd(bd);
if (success = False) then
begin
WriteLn(pubKey.LastErrorText);
Exit;
end;
WriteLn('Loaded a ' + pubKey.KeyType + ' public key.');
bd.Free;
pubKey.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.