AutoIt Requires Chilkat v11.8.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oEmail = ObjCreate("Chilkat.Email")
; The recipient's certificate and private key are in a PEM file. The 2nd argument of LoadPemFile
; is the password of the private key.
$oPem = ObjCreate("Chilkat.Pem")
$bSuccess = $oPem.LoadPemFile("recipient.pem","RECIPIENT_PASSWORD")
If ($bSuccess <> True) Then
ConsoleWrite($oPem.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.AddPemSource($oPem)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oEmail.LoadEml("signed-encrypted.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
If (($oEmail.ReceivedEncrypted <> True) Or ($oEmail.Decrypted <> True)) Then
ConsoleWrite("Expected a successfully decrypted S/MIME envelope." & @CRLF)
Exit
EndIf
If (($oEmail.ReceivedSigned <> True) Or ($oEmail.SignaturesValid <> True)) Then
ConsoleWrite("Expected a valid signature inside the envelope." & @CRLF)
Exit
EndIf
; This message has one signer. Examine its certificate after verification.
$oSigner = ObjCreate("Chilkat.Cert")
$bSuccess = $oEmail.LastSignerCert(0,$oSigner)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Signer certificate: " & $oSigner.SubjectDN & @CRLF)
ConsoleWrite("Recovered subject: " & $oEmail.Subject & @CRLF)
ConsoleWrite("Recovered attachments: " & $oEmail.NumAttachments & @CRLF)