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

Load an EC Public Key from Point Coordinates

Demonstrates the Chilkat PublicKey.LoadEcdsa method, which loads an elliptic-curve public key from its affine point coordinates. The first argument names the curve, the second is the hexadecimal x-coordinate (Qx), and the third is the y-coordinate (Qy).

Background: An EC public key is a point (x, y) on a named curve, so this loader constructs the key from those raw values directly — the option to use when a system hands you the coordinates rather than an encoded key. The curve name (for example secp256r1) is essential, since the same coordinates mean nothing without knowing which curve they lie on.

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

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

procedure RunDemo;
var
  success: Boolean;
  pubKey: TPublicKey;
  curveName: string;
  qx: string;
  qy: string;

begin
  success := False;

  //  Demonstrates the PublicKey.LoadEcdsa method, which loads an elliptic-curve public key from its
  //  affine point coordinates.  The 1st argument names the curve, the 2nd is the hex x-coordinate
  //  (Qx), and the 3rd is the hex y-coordinate (Qy).

  pubKey := TPublicKey.Create;

  curveName := 'secp256r1';
  qx := '1ccbe91c075fc7f4f033bfa248db8fccd3565de94bbfb12f3c59ff46c271bf83';
  qy := 'ce4014c68811f9a21a1fdb2c0e6113e06db7ca93b7404e78dc7ccd5ca89a4ca9';

  success := pubKey.LoadEcdsa(curveName,qx,qy);
  if (success = False) then
    begin
      WriteLn(pubKey.LastErrorText);
      Exit;
    end;

  WriteLn('Loaded an EC public key on ' + curveName);


  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.