Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get Base64 Public Key from Private Key
See more ECC Examples
Demonstrates how to get the public key in base64 format from a private key.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.PrivateKey,
Chilkat.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
privKey: TPrivateKey;
pubKey: TPublicKey;
pubKeyBase64: string;
begin
success := False;
// Load a private key from base64.
bd := TBinData.Create;
success := bd.AppendEncoded('MHQCA....n0Q==','base64');
privKey := TPrivateKey.Create;
success := privKey.LoadAnyFormat(bd,'');
if (success = False) then
begin
WriteLn(privKey.LastErrorText);
Exit;
end;
pubKey := TPublicKey.Create;
privKey.ToPublicKey(pubKey);
pubKeyBase64 := pubKey.GetEncoded(True,'base64');
WriteLn(pubKeyBase64);
bd.Free;
privKey.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.