Sample code for 30+ languages & platforms
Chilkat2-Python

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 Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

pfx = chilkat2.Pfx()

# 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.
bd = chilkat2.BinData()
bLoaded = bd.LoadFile("qa_data/identity.pfx")
if (bLoaded != True):
    print("Failed to load the PFX file.")
    sys.exit()

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

# Load the PFX / PKCS#12 container from the bytes held in the BinData.
success = pfx.LoadPfxBd(bd,password)
if (success == False):
    print(pfx.LastErrorText)
    sys.exit()

print("Loaded " + str(pfx.NumCerts) + " certificate(s).")