Sample code for 30+ languages & platforms
Delphi ActiveX Requires Chilkat v11.0.0+

Decrypt an S/MIME email and verify its signature

See more Email Object Examples

Register the recipient’s PFX before opening signed-encrypted.eml. This workflow expects both encryption and a signature, so it checks both layers before reading the message. Cryptographic signature validity is one input to a signer-trust decision.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
email: TChilkatEmail;
signer: TChilkatCert;

begin
success := 0;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

email := TChilkatEmail.Create(Self);
success := email.AddPfxSourceFile('recipient.pfx','RECIPIENT_PASSWORD');
if (success <> 1) then
  begin
    Memo1.Lines.Add(email.LastErrorText);
    Exit;
  end;
success := email.LoadEml('signed-encrypted.eml');
if (success <> 1) then
  begin
    Memo1.Lines.Add(email.LastErrorText);
    Exit;
  end;
if ((email.ReceivedEncrypted <> 1) or (email.Decrypted <> 1)) then
  begin
    Memo1.Lines.Add('Expected a successfully decrypted S/MIME envelope.');
    Exit;
  end;
if ((email.ReceivedSigned <> 1) or (email.SignaturesValid <> 1)) then
  begin
    Memo1.Lines.Add('Expected a valid signature inside the envelope.');
    Exit;
  end;
//  This message has one signer. Examine its certificate after verification.
signer := TChilkatCert.Create(Self);
success := email.LastSignerCert(0,signer.ControlInterface);
if (success <> 1) then
  begin
    Memo1.Lines.Add(email.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('Signer certificate: ' + signer.SubjectDN);
Memo1.Lines.Add('Recovered subject: ' + email.Subject);
Memo1.Lines.Add('Recovered attachments: ' + IntToStr(email.NumAttachments));