VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set store = CreateObject("Chilkat.CertStore")
success = store.OpenCurrentUserStore(1)
If (success <> 1) Then
outFile.WriteLine(store.LastErrorText)
WScript.Quit
End If
set search = CreateObject("Chilkat.JsonObject")
success = search.UpdateString("thumbprint","YOUR_CERTIFICATE_THUMBPRINT")
set cert = CreateObject("Chilkat.Cert")
success = store.FindCert(search,cert)
If (success <> 1) Then
outFile.WriteLine(store.LastErrorText)
WScript.Quit
End If
If (cert.HasPrivateKey() <> 1) Then
outFile.WriteLine("The selected certificate has no accessible private key.")
WScript.Quit
End If
set privateKey = CreateObject("Chilkat.PrivateKey")
success = cert.GetPrivateKey(privateKey)
If (success <> 1) Then
outFile.WriteLine(cert.LastErrorText)
WScript.Quit
End If
set signer = CreateObject("Chilkat.Dkim")
signer.DkimDomain = "example.com"
signer.DkimSelector = "mail2026"
signer.DkimAlg = "rsa-sha256"
success = signer.SetDkimPrivateKey(privateKey)
If (success <> 1) Then
outFile.WriteLine(signer.LastErrorText)
WScript.Quit
End If
set message = CreateObject("Chilkat.BinData")
success = message.LoadFile("message.eml")
If (success <> 1) Then
outFile.WriteLine("Could not read message.eml.")
WScript.Quit
End If
success = signer.DkimSign(message)
If (success <> 1) Then
outFile.WriteLine(signer.LastErrorText)
WScript.Quit
End If
success = message.WriteFile("signed.eml")
If (success <> 1) Then
outFile.WriteLine("Could not write signed.eml.")
WScript.Quit
End If
outFile.WriteLine("Saved signed.eml.")
outFile.Close