Sample code for 30+ languages & platforms
Lua

Serialize a PFX to BinData

See more PFX/P12 Examples

Demonstrates Pfx.ToBd, which serializes the current PFX contents as PKCS#12 data into a BinData object, using the supplied output password.

Background. This is the in-memory equivalent of ToFile, producing the PKCS#12 bytes for further processing or transport.

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.
-- The PFX password should come from a secure source rather than being hard-coded.
local password = "myPfxPassword"
local success = pfx:load_pfx_file("qa_data/identity.pfx", password)
if not success then
    print(pfx.last_error_text)
    return
end

-- Serialize the PFX contents as PKCS#12 data into a BinData, using the given output password.
local outputPassword = "myOutputPassword"
local bd = chilkat.BinData.new()
success = pfx:to_bd(outputPassword, bd)
if not success then
    print(pfx.last_error_text)
    return
end

print("Serialized " .. bd.num_bytes .. " bytes of PKCS#12 data.")