Delphi DLL Requires Chilkat v11.8.0+
Delphi DLL
Decrypt an S/MIME email and verify its signature
See more Email Object Examples
Register the recipient’s certificate and private key (from a PEM file) 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 DLL Downloads
var
success: Boolean;
email: HCkEmail;
pem: HCkPem;
signer: HCkCert;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := CkEmail_Create();
// The recipient's certificate and private key are in a PEM file. The 2nd argument of LoadPemFile
// is the password of the private key.
pem := CkPem_Create();
success := CkPem_LoadPemFile(pem,'recipient.pem','RECIPIENT_PASSWORD');
if (success <> True) then
begin
Memo1.Lines.Add(CkPem__lastErrorText(pem));
Exit;
end;
success := CkEmail_AddPemSource(email,pem);
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
success := CkEmail_LoadEml(email,'signed-encrypted.eml');
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
if ((CkEmail_getReceivedEncrypted(email) <> True) or (CkEmail_getDecrypted(email) <> True)) then
begin
Memo1.Lines.Add('Expected a successfully decrypted S/MIME envelope.');
Exit;
end;
if ((CkEmail_getReceivedSigned(email) <> True) or (CkEmail_getSignaturesValid(email) <> True)) 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 := CkCert_Create();
success := CkEmail_LastSignerCert(email,0,signer);
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
Memo1.Lines.Add('Signer certificate: ' + CkCert__subjectDN(signer));
Memo1.Lines.Add('Recovered subject: ' + CkEmail__subject(email));
Memo1.Lines.Add('Recovered attachments: ' + IntToStr(CkEmail_getNumAttachments(email)));
CkEmail_Dispose(email);
CkPem_Dispose(pem);
CkCert_Dispose(signer);