Lua
Lua
Examine KeyInfo Certificate in XML Signature
See more XML Digital Signatures Examples
This example loads signed XML and gets the signing certificate, assuming the certificate is contained in X509Certificate within the KeyInfo.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local dsig = chilkat.XmlDSig.new()
local sbXml = chilkat.StringBuilder.new()
local success = sbXml:load_file("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml", "utf-8")
if not success then
print("Failed to load XML file.")
return
end
success = dsig:load_signature_sb(sbXml)
if not success then
print(dsig.last_error_text)
return
end
-- Get the KeyInfo XML.
local xmlKeyInfo = dsig:get_key_info()
if not dsig.last_method_success then
print(dsig.last_error_text)
return
end
print(xmlKeyInfo:get_xml())
print("----")
-- Assuming the X509Certificate is in the KeyInfo, it will look like this:
-- <ds:KeyInfo Id="...">
-- <ds:KeyValue>
-- ...
-- <ds:X509Data>
-- <ds:X509Certificate>MIIHAz...</ds:X509Certificate>
-- </ds:X509Data>
-- </ds:KeyInfo>
local certBase64 = xmlKeyInfo:get_child_content("*:X509Data|*:X509Certificate")
if not xmlKeyInfo.last_method_success then
print("No X509Certificate found in the KeyInfo.")
return
end
-- Load a certificate object w/ the base64.
local cert = chilkat.Cert.new()
success = cert:load_from_base64(certBase64)
if not success then
print(cert.last_error_text)
return
end
-- Examine the cert..
print("SubjectDN: " .. cert.subject_dn)
print("IssuerDN: " .. cert.issuer_dn)
print("SerialNumber as Decimal: " .. cert.serial_decimal)