Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get the Signer Certificate of a Signed Email
See more Email Object Examples
Demonstrates the Chilkat Email.LastSignerCert method, which copies the certificate for the signer at a given zero-based index into a Cert object. Most signed emails have one signer (index 0), but a message can have more than one. This example loads a signed email and reads the first signer's common name.
Background: Confirming that a signature is valid (see
SignaturesValid) tells you the content wasn't altered, but not who signed it. LastSignerCert gives you the signer's certificate as an object so you can examine its subject and issuer and evaluate trust — an essential step before relying on a signature to establish the sender's identity.Chilkat Pascal (Lazarus/Delphi) Downloads
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,
Chilkat.Cert;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
cert: TCert;
begin
success := False;
// Demonstrates the LastSignerCert method, which copies the certificate for the signer at
// the given zero-based index into a Cert object. Most signed emails have one signer
// (index 0), but a message can have more than one.
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
// Get the certificate of the first signer (index 0).
cert := TCert.Create;
success := email.LastSignerCert(0,cert);
if (success = True) then
begin
WriteLn('Signer certificate (CN): ' + cert.SubjectCN);
end;
end;
// Note: The path "qa_data/..." is a relative local filesystem path,
// relative to the current working directory of the running application.
email.Free;
cert.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.