Lua Requires Chilkat v11.0.0+
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local message = chilkat.BinData.new()
local success = message:load_file("signed.eml")
if not success then
print("Could not read signed.eml.")
return
end
local verifier = chilkat.Dkim.new()
local domain = "example.com"
local selector = "mail2026"
local keyText = chilkat.StringBuilder.new()
success = keyText:load_file("dkim-public.pem", "utf-8")
if not success then
print("Could not read the trusted public PEM.")
return
end
success = verifier:load_public_key(selector, domain, keyText:get_as_string())
if not success then
print(verifier.last_error_text)
return
end
-- signed.eml from the signing example has our newly added signature at index zero.
if verifier:num_dkim_sigs(message) == 0 then
print("No DKIM signature in signed.eml.")
return
end
success = verifier:dkim_verify(0, message)
if not success then
print(verifier.last_error_text)
print(verifier.verify_info)
return
end
local info = chilkat.JsonObject.new()
success = info:load(verifier.verify_info)
if (not success) or ((not info:string_of_equals("domain", domain, true)) or (not info:string_of_equals("selector", selector, true))) then
print("The first signature is not from the selected domain and selector.")
return
end
print("The configured public key verifies this message.")