Lua
Lua
Get PDF Signer Certs
See more PDF Signatures Examples
This example demonstrates how to validate the signatures in a PDF and also shows how to getChilkat 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 pdf = chilkat.Pdf.new()
-- Load a PDF that has cryptographic signatures to be validated
local success = pdf:load_file("qa_data/pdf/sign_testing_1/helloSigned2.pdf")
if not success then
print(pdf.last_error_text)
return
end
-- Each time we verify a signature, information about the signature is written into
-- sigInfo (replacing whatever sigInfo previously contained).
local sigInfo = chilkat.JsonObject.new()
-- Iterate over each signature and validate each.
local numSignatures = pdf.num_signatures
local validated = false
local cert = chilkat.Cert.new()
local i = 0
while i < numSignatures do
validated = pdf:verify_signature(i, sigInfo)
print("Signature " .. i .. " validated: " .. tostring(validated))
-- After calling VerifySignature, you can get the signer certificate by calling
-- GetSignerCert with the same index.
success = pdf:get_signer_cert(i, cert)
if success then
print("PDF signer certificate: " .. cert.subject_dn)
end
i = i + 1
end
print("Finished.")