Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Crypt2.ClearSigningCerts method

Demonstrates how to call the ClearSigningCerts 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.BinData,
  Chilkat.Cert,
  Chilkat.Crypt2;

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

procedure RunDemo;
var
  success: Boolean;
  crypt: TCrypt2;
  cert1: TCert;
  cert2: TCert;
  cert3: TCert;
  bd: TBinData;
  cert4: TCert;
  cert5: TCert;

begin
  success := False;

  crypt := TCrypt2.Create;
  success := False;

  //  Tell the crypt object to use 3 certificates.
  //  Do this by calling AddSigningCert for each certificate.

  cert1 := TCert.Create;
  //  ...
  //  Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
  //  ...
  crypt.AddSigningCert(cert1);

  cert2 := TCert.Create;
  //  ...
  crypt.AddSigningCert(cert2);

  cert3 := TCert.Create;
  //  ...
  crypt.AddSigningCert(cert3);

  bd := TBinData.Create;
  //  ...

  success := crypt.OpaqueSignBd(bd);

  //  Let's say we now want to sign something else with different certs..
  //  First clear the signing certs.
  crypt.ClearSigningCerts();

  cert4 := TCert.Create;
  //  ...
  crypt.AddSigningCert(cert4);

  cert5 := TCert.Create;
  //  ...
  crypt.AddSigningCert(cert5);

  //  ...
  //  ...

  //  Sign using cert4 and cert5.
  success := crypt.OpaqueSignBd(bd);


  crypt.Free;
  cert1.Free;
  cert2.Free;
  cert3.Free;
  bd.Free;
  cert4.Free;
  cert5.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.