AutoIt Requires Chilkat v11.0.0+
AutoIt
Sign an email with a key in the Windows Current User certificate store
See more DKIM Examples
Run on Windows as the account that owns the signing certificate. Copy its thumbprint from Current User > Personal and supply it as hexadecimal digits. The thumbprint selects a certificate. The DKIM signature itself uses RSA-SHA256.
The certificate needs an accessible, exportable RSA private key for GetPrivateKey. Publish its matching public key under the selector in DNS. DKIM recipients use that DNS key to verify the message. An X.509 chain is unnecessary for this step.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oStore = ObjCreate("Chilkat.CertStore")
$bSuccess = $oStore.OpenCurrentUserStore(True)
If ($bSuccess <> True) Then
ConsoleWrite($oStore.LastErrorText & @CRLF)
Exit
EndIf
$oSearch = ObjCreate("Chilkat.JsonObject")
$oSearch.UpdateString("thumbprint","YOUR_CERTIFICATE_THUMBPRINT")
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oStore.FindCert($oSearch,$oCert)
If ($bSuccess <> True) Then
ConsoleWrite($oStore.LastErrorText & @CRLF)
Exit
EndIf
If ($oCert.HasPrivateKey() <> True) Then
ConsoleWrite("The selected certificate has no accessible private key." & @CRLF)
Exit
EndIf
$oPrivateKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oCert.GetPrivateKey($oPrivateKey)
If ($bSuccess <> True) Then
ConsoleWrite($oCert.LastErrorText & @CRLF)
Exit
EndIf
$oSigner = ObjCreate("Chilkat.Dkim")
$oSigner.DkimDomain = "example.com"
$oSigner.DkimSelector = "mail2026"
$oSigner.DkimAlg = "rsa-sha256"
$bSuccess = $oSigner.SetDkimPrivateKey($oPrivateKey)
If ($bSuccess <> True) Then
ConsoleWrite($oSigner.LastErrorText & @CRLF)
Exit
EndIf
$oMessage = ObjCreate("Chilkat.BinData")
$bSuccess = $oMessage.LoadFile("message.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Could not read message.eml." & @CRLF)
Exit
EndIf
$bSuccess = $oSigner.DkimSign($oMessage)
If ($bSuccess <> True) Then
ConsoleWrite($oSigner.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oMessage.WriteFile("signed.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Could not write signed.eml." & @CRLF)
Exit
EndIf
ConsoleWrite("Saved signed.eml." & @CRLF)