Lua Requires Chilkat v11.0.0+
Lua
Sign an EML using RSA-PSS and SHA-256
See more Email Object Examples
Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local email = chilkat.Email.new()
local success = email:load_eml("message.eml")
if not success then
print(email.last_error_text)
return
end
local cert = chilkat.Cert.new()
success = cert:load_pfx_file("signer.pfx", "PFX_PASSWORD")
if not success then
print(cert.last_error_text)
return
end
success = email:set_signing_cert(cert)
if not success then
print(email.last_error_text)
return
end
email.signing_alg = "pss"
email.signing_hash_alg = "sha256"
email.send_signed = true
local mail = chilkat.MailMan.new()
mail.opaque_signing = false
local rendered = chilkat.BinData.new()
success = mail:render_to_mime_bd(email, rendered)
if not success then
print(mail.last_error_text)
return
end
success = rendered:write_file("signed.eml")
if not success then
print("Failed: rendered.WriteFile.")
return
end
print("Saved signed.eml.")