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

Convert to DER encoded X.509 Certificate (.cer, .crt)

See more Certificates Examples

Loads a digital certificate from any format and saves to a binary DER encoded X.509 Certificate (.cer, .crt).

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

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

procedure RunDemo;
var
  success: Boolean;
  cert: TCert;

begin
  success := False;

  cert := TCert.Create;

  //  LoadFromFile will load virtually any certificate format file.
  //  It will auto-recognize the format and load appropiately.
  //  In this case, load a PEM format certificate and convert to DER.
  success := cert.LoadFromFile('/Users/chilkat/testData/pem/chilkat.pem');
  if (success <> True) then
    begin
      WriteLn(cert.LastErrorText);
      Exit;
    end;

  success := cert.ExportCertDerFile('chilkat.der');
  if (success <> True) then
    begin
      WriteLn(cert.LastErrorText);
      Exit;
    end;

  WriteLn('Converted certificate from PEM to DER format.');


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