Sample code for 30+ languages & platforms
Lazarus Pascal

Verify the Timestamp Server Token (if any) while Validating a CMS Signature

Demonstrates how to also validate the timestamp server token (if any) while validating a CMS signature.

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

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

procedure RunDemo;
var
  success: Boolean;
  crypt: TCrypt2;
  cmsOptions: TJsonObject;
  outputFile: string;
  inFile: string;

begin
  success := False;

  crypt := TCrypt2.Create;

  //  Tell Chilkat to also validate the timestamp token if a timestamp exists in the CMS message's unauthenticated attributes.
  cmsOptions := TJsonObject.Create;
  cmsOptions.UpdateBool('ValidateTimestampTokens',True);
  crypt.CmsOptions := cmsOptions.Emit();

  outputFile := 'qa_output/original.xml';
  inFile := 'qa_data/p7m/fattura_signature.xml.p7m';

  //  Verify the signature and extract the contained file, which in this case is XML.
  success := crypt.VerifyP7M(inFile,outputFile);
  if (success = False) then
    begin
      WriteLn(crypt.LastErrorText);
      Exit;
    end;

  WriteLn('Signature validated.');


  crypt.Free;
  cmsOptions.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.