Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loMessage
LOCAL loVerifier
LOCAL lcDomain
LOCAL lcSelector
LOCAL loKeyText
LOCAL loInfo
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loMessage = CreateObject('Chilkat.BinData')
lnSuccess = loMessage.LoadFile("signed.eml")
IF (lnSuccess <> 1) THEN
? "Could not read signed.eml."
RELEASE loMessage
CANCEL
ENDIF
loVerifier = CreateObject('Chilkat.Dkim')
lcDomain = "example.com"
lcSelector = "mail2026"
loKeyText = CreateObject('Chilkat.StringBuilder')
lnSuccess = loKeyText.LoadFile("dkim-public.pem","utf-8")
IF (lnSuccess <> 1) THEN
? "Could not read the trusted public PEM."
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
CANCEL
ENDIF
lnSuccess = loVerifier.LoadPublicKey(lcSelector,lcDomain,loKeyText.GetAsString())
IF (lnSuccess <> 1) THEN
? loVerifier.LastErrorText
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
CANCEL
ENDIF
* signed.eml from the signing example has our newly added signature at index zero.
IF (loVerifier.NumDkimSigs(loMessage) = 0) THEN
? "No DKIM signature in signed.eml."
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
CANCEL
ENDIF
lnSuccess = loVerifier.DkimVerify(0,loMessage)
IF (lnSuccess <> 1) THEN
? loVerifier.LastErrorText
? loVerifier.VerifyInfo
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
CANCEL
ENDIF
loInfo = CreateObject('Chilkat.JsonObject')
lnSuccess = loInfo.Load(loVerifier.VerifyInfo)
IF ((lnSuccess <> 1) OR (loInfo.StringOfEquals("domain",lcDomain,1) <> 1) OR (loInfo.StringOfEquals("selector",lcSelector,1) <> 1)) THEN
? "The first signature is not from the selected domain and selector."
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
RELEASE loInfo
CANCEL
ENDIF
? "The configured public key verifies this message."
RELEASE loMessage
RELEASE loVerifier
RELEASE loKeyText
RELEASE loInfo