DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vSigner
Handle hoSigner
String sTemp1
Integer iTemp1
Boolean bTemp1
Boolean bTemp2
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Get ComAddPfxSourceFile Of hoEmail "recipient.pfx" "RECIPIENT_PASSWORD" To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLoadEml Of hoEmail "signed-encrypted.eml" To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComReceivedEncrypted Of hoEmail To bTemp1
Get ComDecrypted Of hoEmail To bTemp2
If ((bTemp1 <> True) Or (bTemp2 <> True)) Begin
Showln "Expected a successfully decrypted S/MIME envelope."
Procedure_Return
End
Get ComReceivedSigned Of hoEmail To bTemp1
Get ComSignaturesValid Of hoEmail To bTemp2
If ((bTemp1 <> True) Or (bTemp2 <> True)) Begin
Showln "Expected a valid signature inside the envelope."
Procedure_Return
End
// This message has one signer. Examine its certificate after verification.
Get Create (RefClass(cComChilkatCert)) To hoSigner
If (Not(IsComObjectCreated(hoSigner))) Begin
Send CreateComObject of hoSigner
End
Get pvComObject of hoSigner to vSigner
Get ComLastSignerCert Of hoEmail 0 vSigner To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSubjectDN Of hoSigner To sTemp1
Showln "Signer certificate: " sTemp1
Get ComSubject Of hoEmail To sTemp1
Showln "Recovered subject: " sTemp1
Get ComNumAttachments Of hoEmail To iTemp1
Showln "Recovered attachments: " iTemp1
End_Procedure