Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load a Public Key from Base64 DER
Demonstrates the Chilkat PublicKey.LoadBase64 method, which loads a public key from standard Base64-encoded DER. The only argument is the Base64 string; whitespace within it is permitted.
Background: A public key in DER (binary) form is often carried as Base64 text so it can travel through channels that expect a string — a config value, a JSON field, a certificate export. This loader decodes that text and inspects the DER to determine the key type and structure automatically. It is the plain-Base64 counterpart to loading a full PEM block, which additionally has the
BEGIN/END armor.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.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pubKey: TPublicKey;
keyStr: string;
begin
success := False;
// Demonstrates the PublicKey.LoadBase64 method, which loads a public key from standard
// Base64-encoded DER. The only argument is the Base64 string (whitespace is allowed).
pubKey := TPublicKey.Create;
// The Base64 of the DER-encoded public key.
keyStr := 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...IDAQAB';
success := pubKey.LoadBase64(keyStr);
if (success = False) then
begin
WriteLn(pubKey.LastErrorText);
Exit;
end;
WriteLn('Loaded a ' + pubKey.KeyType + ' public key.');
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.