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

Get an S/MIME Signing Time

See more MIME Examples

Demonstrates the Chilkat Mime.GetSignatureSigningTimeStr method, which returns the CMS signingTime attribute for the signer at a zero-based index, as an RFC 822-style date string in GMT. The only argument is the signer index.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: This is the timestamp the signer asserted at signing — useful for "when was this signed" audit trails and for evaluating whether the signing certificate was valid at that moment. Because it is a signed attribute, it is tamper-evident. Guard the call with HasSignatureSigningTime, since the attribute is optional. Note it is the signer's claim, not a trusted third-party timestamp.

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

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

procedure RunDemo;
var
  success: Boolean;
  mime: TMime;
  n: Integer;
  i: Integer;
  signingTime: string;

begin
  success := False;

  mime := TMime.Create;
  success := mime.LoadMimeFile('qa_data/signed.eml');
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  //  After verifying, get the CMS signingTime for each signer that has one, as an RFC 822 date string
  //  in GMT.  The only argument is the zero-based signer index.
  success := mime.Verify();
  if (success <> True) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  n := mime.NumSignerCerts;

  for i := 0 to n - 1 do
    begin
      //  Only signers that included a signing time have one to retrieve.
      if (mime.HasSignatureSigningTime(i)) then
        begin
          signingTime := mime.GetSignatureSigningTimeStr(i);
          if (mime.LastMethodSuccess = False) then
            begin
              WriteLn(mime.LastErrorText);
              Exit;
            end;
          WriteLn('Signer ' + i + ' signing time: ' + signingTime);
        end;
    end;



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