Sample code for 30+ languages & platforms
Lua

Load a PFX from BinData

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxBd, which loads a PFX / PKCS#12 container from the bytes held in a BinData object.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. This is the in-memory equivalent of LoadPfxFile, for when the PKCS#12 data is already available as bytes rather than in a file.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local pfx = chilkat.Pfx.new()

-- The file path is relative to the application's current working directory.  An absolute path
-- may also be used.  Supply the path appropriate to your own environment.
-- Load the PFX bytes into a BinData.
local bd = chilkat.BinData.new()
local bLoaded = bd:load_file("qa_data/identity.pfx")
if not bLoaded then
    print("Failed to load the PFX file.")
    return
end

-- The PFX password should come from a secure source rather than being hard-coded.
local password = "myPfxPassword"

-- Load the PFX / PKCS#12 container from the bytes held in the BinData.
local success = pfx:load_pfx_bd(bd, password)
if not success then
    print(pfx.last_error_text)
    return
end

print("Loaded " .. pfx.num_certs .. " certificate(s).")