AutoIt Requires Chilkat v11.0.0+
AutoIt
Verify DKIM using a public key supplied as text
See more DKIM Examples
Applications that keep public keys in configuration can pass a complete PEM string or the base64 value of the DNS p= tag to LoadPublicKey. This example reads a trusted PEM as text so it can be run alongside the file-based example. Supply just the key material when passing a base64 value. Reuse the same verifier for signatures with that exact domain and selector.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oMessage = ObjCreate("Chilkat.BinData")
$bSuccess = $oMessage.LoadFile("signed.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Could not read signed.eml." & @CRLF)
Exit
EndIf
$oVerifier = ObjCreate("Chilkat.Dkim")
Local $sDomain = "example.com"
Local $selector = "mail2026"
$oKeyText = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oKeyText.LoadFile("dkim-public.pem","utf-8")
If ($bSuccess <> True) Then
ConsoleWrite("Could not read the trusted public PEM." & @CRLF)
Exit
EndIf
$bSuccess = $oVerifier.LoadPublicKey($selector,$sDomain,$oKeyText.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite($oVerifier.LastErrorText & @CRLF)
Exit
EndIf
; signed.eml from the signing example has our newly added signature at index zero.
If ($oVerifier.NumDkimSigs($oMessage) = 0) Then
ConsoleWrite("No DKIM signature in signed.eml." & @CRLF)
Exit
EndIf
$bSuccess = $oVerifier.DkimVerify(0,$oMessage)
If ($bSuccess <> True) Then
ConsoleWrite($oVerifier.LastErrorText & @CRLF)
ConsoleWrite($oVerifier.VerifyInfo & @CRLF)
Exit
EndIf
$oInfo = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oInfo.Load($oVerifier.VerifyInfo)
If (($bSuccess <> True) Or ($oInfo.StringOfEquals("domain",$sDomain,True) <> True) Or ($oInfo.StringOfEquals("selector",$selector,True) <> True)) Then
ConsoleWrite("The first signature is not from the selected domain and selector." & @CRLF)
Exit
EndIf
ConsoleWrite("The configured public key verifies this message." & @CRLF)