Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Crypt2.SetSigningCert method

Demonstrates how to call the SetSigningCert method.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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,
  Chilkat.Crypt2;

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

procedure RunDemo;
var
  success: Boolean;
  cryptA: TCrypt2;
  certA: TCert;
  cryptB: TCrypt2;
  certB: TCert;
  cryptC: TCrypt2;
  certC: TCert;

begin
  success := False;

  //  Signing certificates can be obtained from many different sources..

  //  Load from a PFX
  cryptA := TCrypt2.Create;
  certA := TCert.Create;
  success := certA.LoadPfxFile('c:/someDir/pfx_files/a.pfx','pfx_file_password');
  success := cryptA.SetSigningCert(certA);
  //  ...

  //  Load from a smart card or USB token.
  cryptB := TCrypt2.Create;
  certB := TCert.Create;
  certB.SmartCardPin := '123456';
  success := certB.LoadFromSmartcard('');
  success := cryptB.SetSigningCert(certB);
  //  ...

  //  Load from a the Windows certificate store or macOS keychain
  cryptC := TCrypt2.Create;
  certC := TCert.Create;
  success := certC.LoadByCommonName('Xyz 123');
  success := cryptC.SetSigningCert(certC);
  //  ...


  cryptA.Free;
  certA.Free;
  cryptB.Free;
  certB.Free;
  cryptC.Free;
  certC.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.