Sample code for 30+ languages & platforms
Lua

Verify XML Digital Signature

See more XML Digital Signatures Examples

Verifies XML signatures in an XML file.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local sbXml = chilkat.StringBuilder.new()
local success = sbXml:load_file("qa_data/xml_dsig_verify/csioz_sample.xml", "utf-8")
if not success then
    print("Failed to load XML file.")
    return
end

local dsig = chilkat.XmlDSig.new()

-- First load the XML containing the signatures to be verified.
success = dsig:load_signature_sb(sbXml)
if not success then
    print(dsig.last_error_text)
    return
end

-- It's possible that an XML document can contain multiple signatures.
-- Each can be verified as follows:
local i = 0
while i < dsig.num_signatures do
    -- Select the Nth signature by setting the Selector property.
    dsig.selector = i

    -- The bVerifyReferenceDigests argument determines if we want
    -- to also verify each reference digest.  If set to false,
    -- then only the SignedInfo part of the Signature is verified.
    local bVerifyReferenceDigests = true
    local bVerified = dsig:verify_signature(bVerifyReferenceDigests)
    print("Signature " .. (i + 1) .. " verified = " .. tostring(bVerified))

    i = i + 1
end