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

Convert DSA DER Private Key to PEM

See more DSA Examples

Converts a DSA private key from DER format to PEM. Demonstrates how to write both encrypted and unencrypted PEM formatted private keys.

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;
  pemStr: 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;

  //  Load a DER private key.
  success := dsa.FromDerFile('dsa_priv.der');
  if (success <> True) then
    begin
      WriteLn(dsa.LastErrorText);
      Exit;
    end;

  //  Save to unencrypted PEM:
  pemStr := dsa.ToPem();
  success := dsa.SaveText(pemStr,'dsa_priv.pem');
  if (success <> True) then
    begin
      WriteLn(dsa.LastErrorText);
      Exit;
    end;

  //  Save to encrypted PEM:
  pemStr := dsa.ToEncryptedPem('myPassword');
  success := dsa.SaveText(pemStr,'dsa_privEncrypted.pem');
  if (success <> True) then
    begin
      WriteLn(dsa.LastErrorText);
      Exit;
    end;

  WriteLn('Finished!');


  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.