Xbase++ Requires Chilkat v11.0.0+
Xbase++
Load Certificate from PFX (PKCS#12)
See more Certificates Examples
Loads a digital certificate (and private key, if available) from a PFX file.(also known as PKCS#12)Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oCert
LOCAL cPfxFilename
LOCAL cPfxPassword
LOCAL oPrivKey
LOCAL cPemPassword
LOCAL cPemPath
nSuccess := 0
oCert := CreateObject("Chilkat.Cert")
// Load from the PFX file
cPfxFilename := "/Users/chilkat/testData/pfx/chilkat_ssl_pwd_is_test.pfx"
cPfxPassword := "test"
// A PFX typically contains certificates in the chain of authentication.
// The Chilkat cert object will choose the certificate w/
// private key farthest from the root authority cert.
// To access all the certificates in a PFX, use the
// Chilkat certificate store object instead.
nSuccess := oCert:LoadPfxFile(cPfxFilename, cPfxPassword)
IF (nSuccess == 0)
? oCert:LastErrorText
oCert:destroy()
RETURN
ENDIF
// Get some information about the digital certificate,
// then get the private key...
// DN = "Distinguished Name"
? "SubjectDN:" + oCert:SubjectDN
? "Common Name:" + oCert:SubjectCN
? "Issuer Common Name:" + oCert:IssuerCN
? "Serial Number:" + oCert:SerialNumber
oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oCert:GetPrivateKey(oPrivKey)
IF (nSuccess == 0)
? oCert:LastErrorText
oCert:destroy()
oPrivKey:destroy()
RETURN
ENDIF
// The private key object may be used in any Chilkat methods
// (in other objects/classes) that expect a private key argument.
// In this case, save the private key to a PKCS8 Encrypted PEM format file:
cPemPassword := "secret"
cPemPath := "/Users/chilkat/testData/pem/chilkat_privKey.pem"
nSuccess := oPrivKey:SavePkcs8EncryptedPemFile(cPemPassword, cPemPath)
IF (nSuccess == 0)
? oPrivKey:LastErrorText
oCert:destroy()
oPrivKey:destroy()
RETURN
ENDIF
? "Private key saved to PKCS8 Encrypted PEM..."
oCert:destroy()
oPrivKey:destroy()