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

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat Lua Downloads

Lua

    -- In the following call to loadlib, change the path (./chilkat.dll) to the relative or absolute directory where the chilkat.dll, chilkat.so, or chilkat.dylib is located.
    chilkat = assert(package.loadlib("./chilkat.dll", "luaopen_chilkat"))()
    print(chilkat._VERSION)

    local success = false

    local certStore = chilkat.newCertStore{}

    --  This only loads the contents of the PFX file into the certStore object.
    --  It is not importing the PFX into the Windows certificate stores.
    local pfxPassword = "badssl.com"
    success = certStore:LoadPfxFile("qa_data/pfx/badssl.com-client.p12",pfxPassword)
    if success == false then
        print(certStore:LastErrorText())

    end

    --  Examine each certificate (loaded from the PFX) in this certStore object
    local cert = chilkat.newCert{}
    local numCerts = certStore:NumCertificates()
    local i = 0
    while i < numCerts do
        certStore:GetCert(i,cert)
        print("hasPrivateKey=", cert:HasPrivateKey(), ", ", cert:SubjectCN())
        i = i + 1
    end