Lua Requires Chilkat v9.5.0.75+
Lua
Create Egypt ITIDA CAdES-BES .p7s Signature (with strings in-memory)
See more Egypt ITIDA Examples
Demonstrates how to create a .p7s signature that fits Egypt's ITIDA requirements.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local crypt = chilkat.Crypt2.new()
local cert = chilkat.Cert.new()
-- There are many ways to load the certificate.
-- This example was created for a customer using an ePass2003 USB token.
-- Assuming the USB token is the only source of a hardware-based private key..
local success = cert:load_from_smartcard("")
if not success then
print(cert.last_error_text)
return
end
-- Tell the crypt component to use this cert.
success = crypt:set_signing_cert(cert)
if not success then
print(crypt.last_error_text)
return
end
local cmsOptions = chilkat.JsonObject.new()
-- Setting "DigestData" causes OID 1.2.840.113549.1.7.5 (digestData) to be used.
cmsOptions:update_bool("DigestData", true)
cmsOptions:update_bool("OmitAlgorithmIdNull", true)
crypt.cms_options = cmsOptions:emit()
-- The CadesEnabled property applies to all methods that create CMS/PKCS7 signatures.
-- To create a CAdES-BES signature, set this property equal to true.
crypt.cades_enabled = true
crypt.hash_algorithm = "sha256"
local jsonSigningAttrs = chilkat.JsonObject.new()
jsonSigningAttrs:update_int("contentType", 1)
jsonSigningAttrs:update_int("signingTime", 1)
jsonSigningAttrs:update_int("messageDigest", 1)
jsonSigningAttrs:update_int("signingCertificateV2", 1)
crypt.signing_attributes = jsonSigningAttrs:emit()
-- By default, all the certs in the chain of authentication are included in the signature.
-- If desired, we can choose to only include the signing certificate:
crypt.include_cert_chain = false
-- Make sure we sign the utf-8 byte representation of the JSON string
crypt.charset = "utf-8"
-- Create the CAdES-BES signature.
local textToSign = "\"issuer\"\"address\"\"branchID\"\"0\"\"country\"\"EG\"\"regionCity..."
crypt.encoding_mode = "base64"
local sigBase64 = crypt:sign_string_enc(textToSign)
if not crypt.last_method_success then
print(crypt.last_error_text)
return
end
print("Base64 signature:")
print(sigBase64)