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

Load EC Public Key from X,Y Values

See more ECC Examples

Demonstrates how to load an EC public key from X and Y values.

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.JsonObject,
  Chilkat.PublicKey;

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

procedure RunDemo;
var
  success: Boolean;
  x: string;
  y: string;
  json: TJsonObject;
  pubkey: TPublicKey;

begin
  success := False;

  //  We have the following x and y values in base64 (for an EC point on the P-256 curve).
  x := 'Dn7uB1O7kgk74G6qfQwFJESeDnxO6lLjGZFWZJE16tw';
  y := 'iOWA5DInzK6nuUGvHJbMVq1Dpj248FqSV2teN3HzmhU';

  //  Build a JWK that looks like this:

  //  {
  //    "kty": "EC",
  //    "crv": "P-256",
  //    "x": "Dn7uB1O7kgk74G6qfQwFJESeDnxO6lLjGZFWZJE16tw",
  //    "y": "iOWA5DInzK6nuUGvHJbMVq1Dpj248FqSV2teN3HzmhU"
  //  }

  json := TJsonObject.Create;
  json.UpdateString('kty','EC');
  json.UpdateString('crv','P-256');
  json.UpdateString('x',x);
  json.UpdateString('y',y);

  //  Load from the JWK.
  pubkey := TPublicKey.Create;
  success := pubkey.LoadFromString(json.Emit());
  if (success = False) then
    begin
      WriteLn(pubkey.LastErrorText);
      Exit;
    end;

  WriteLn('Success.');


  json.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.