Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.77+

Convert CRL PEM to XML

See more PEM Examples

Loads a CRL (Certificate Revocation List) from the PEM file format and converts to XML to allow for visual examination and parsing.

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 pem = chilkat.Pem.new()

pem.verbose_logging = true
local success = pem:load_pem_file("qa_data/crl/sampleCrl.pem", "password_not_used")
if not success then
    print(pem.last_error_text)
    return
end

local numCrls = pem.num_crls
local i = 0

local asn = chilkat.Asn.new()
local xml = chilkat.Xml.new()
while i < numCrls do
    -- Get the CRL as base64 (multi-line)
    local crlBase64 = pem:get_encoded_item("crl", "", "base64_mime", i)
    if not pem.last_method_success then
        print(pem.last_error_text)
        return
    end

    print(crlBase64)

    success = asn:load_encoded(crlBase64, "base64")
    if not success then
        print(asn.last_error_text)
        return
    end

    -- Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
    xml:load_xml(asn:asn_to_xml())
    print(xml:get_xml())

    -- Use this online tool to generate parsing code from CRL XML:
    -- Generate Parsing Code from XML

    print("-------------------------------------")
    i = i + 1
end