Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

Verify a signed message with a trusted public key file

See more DKIM Examples

Use the saved signed message and its matching public PEM file to test a signing configuration before publishing DNS. This verifier caches the key for the exact selector and domain. A different pair can trigger normal DNS lookup, so the example also checks which signature actually verified.

Load the key from a trusted source independent of the received message. A pass with a locally supplied key confirms the cryptographic match. Use the published-key check to test what recipients can retrieve.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMessage
LOCAL loVerifier
LOCAL lcDomain
LOCAL lcSelector
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"
lnSuccess = loVerifier.LoadPublicKeyFile(lcSelector,lcDomain,"dkim-public.pem")
IF (lnSuccess <> 1) THEN
    ? loVerifier.LastErrorText
    RELEASE loMessage
    RELEASE loVerifier
    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
    CANCEL
ENDIF

lnSuccess = loVerifier.DkimVerify(0,loMessage)
IF (lnSuccess <> 1) THEN
    ? loVerifier.LastErrorText
    ? loVerifier.VerifyInfo
    RELEASE loMessage
    RELEASE loVerifier
    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 loInfo
    CANCEL
ENDIF

? "Signature verified with the saved key for " + lcSelector + "._domainkey." + lcDomain

RELEASE loMessage
RELEASE loVerifier
RELEASE loInfo