Sample code for 30+ languages & platforms
Lua Requires Chilkat v10.1.2+

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local certStore = chilkat.CertStore.new()

local pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx"
local pfxPassword = "test"
local success = certStore:load_pfx_file(pfxPath, pfxPassword)
if not success then
    print(certStore.last_error_text)
    return
end

local numCerts = certStore.num_certificates

print("PFX contains " .. numCerts .. " certificates")

local cert = chilkat.Cert.new()
local i = 0
while i < numCerts do
    certStore:get_cert(i, cert)

    print(i .. ": (Common Name) " .. cert.subject_cn)
    print(i .. ": (Serial Number) " .. cert.serial_number)
    print(i .. ": (Distinguished Name) " .. cert.subject_dn)

    i = i + 1
end