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

DSA Get Key as XML

Gets the DSA key in XML format.

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

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

procedure RunDemo;
var
  success: Boolean;
  dsa: TDsa;
  bPublicOnly: Boolean;
  xmlStr: string;

begin
  success := False;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  dsa := TDsa.Create;

  //  Generate a new 2048 bit DSA key.
  success := dsa.GenKey(2048);
  if (success <> True) then
    begin
      WriteLn(dsa.LastErrorText);
      Exit;
    end;

  //  Get the public key as XML
  bPublicOnly := True;
  xmlStr := dsa.ToXml(bPublicOnly);
  WriteLn(xmlStr);

  //  Sample output.

  //  <DSAKeyValue>
  //  	<P>wBYOKu...2eoXw==</P>
  //  	<Q>1taJI7...kV2/9c=</Q>
  //  	<G>qjfbTi...eB1+g==</G>
  //  	<Y>t3tz...NqjsPEg==</Y>
  //  </DSAKeyValue>

  //  Get the private key as XML.
  bPublicOnly := False;
  xmlStr := dsa.ToXml(bPublicOnly);

  WriteLn(xmlStr);

  //  Sample output.

  //  <DSAKeyValue>
  //  	<P>wBYOKu...2eoXw==</P>
  //  	<Q>1taJI7...kV2/9c=</Q>
  //  	<G>qjfbTi...eB1+g==</G>
  //  	<Y>t3tz...NqjsPEg==</Y>
  //  	<X>lm9F...XzuVO+qU=</X>
  //  </DSAKeyValue>


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