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

Verify the Digital Signatures on an Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.SignaturesValid property, which is true when the email was received with one or more digital signatures and all of them validated, indicating the message was not altered. It is only meaningful when ReceivedSigned is true, so this example checks that first.

Background: A valid signature proves integrity — the bytes that were signed are exactly the bytes you received — but that is not the same as trust. A message can carry a perfectly valid signature from a certificate you have no reason to trust (self-signed, expired, or from an unknown issuer). So after confirming SignaturesValid, an application that needs assurance of who signed should separately examine the signer certificate and its chain (see LastSignerCert).

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

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

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;

begin
  success := False;

  //  Demonstrates the read-only Email.SignaturesValid property, which is true if the email
  //  was received with one or more digital signatures AND all of them validated (indicating
  //  the email was not altered).  It is only meaningful when ReceivedSigned is true.

  email := TEmail.Create;

  success := email.LoadEml('qa_data/eml/signed.eml');
  if (success = False) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  if (email.ReceivedSigned = True) then
    begin
      if (email.SignaturesValid = True) then
        begin
          WriteLn('The signature(s) verified: the email was not altered.');
        end
      else
        begin
          WriteLn('Signature verification FAILED.');
        end;
    end
  else
    begin
      WriteLn('This email was not received with a digital signature.');
    end;

  //  Note: Paths such as "qa_data/..." are relative local filesystem paths,
  //  relative to the current working directory of the running application.


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