Visual FoxPro
Visual FoxPro
Add a Private Key and Certificate Chain to a PFX
See more PFX/P12 Examples
Demonstrates Pfx.AddPrivateKey, which adds a private key together with its certificate chain to the PFX 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. The chain must contain at least one certificate; the certificate at index 0 is treated as the leaf. The chain is built here with Cert.BuildCertChain.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPfx
LOCAL loPrivKey
LOCAL loCert
LOCAL loChain
lnSuccess = 0
loPfx = CreateObject('Chilkat.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 private key.
loPrivKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivKey.LoadPemFile("qa_data/private_key.pem")
IF (lnSuccess = 0) THEN
? loPrivKey.LastErrorText
RELEASE loPfx
RELEASE loPrivKey
CANCEL
ENDIF
* Load the certificate and build its chain of authority. The chain must contain at least one
* certificate; the certificate at index 0 is treated as the leaf.
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/cert.pem")
IF (lnSuccess = 0) THEN
? loCert.LastErrorText
RELEASE loPfx
RELEASE loPrivKey
RELEASE loCert
CANCEL
ENDIF
loChain = CreateObject('Chilkat.CertChain')
lnSuccess = loCert.BuildCertChain(loChain)
IF (lnSuccess = 0) THEN
? loCert.LastErrorText
RELEASE loPfx
RELEASE loPrivKey
RELEASE loCert
RELEASE loChain
CANCEL
ENDIF
* Add the private key and its certificate chain to the PFX.
lnSuccess = loPfx.AddPrivateKey(loPrivKey,loChain)
IF (lnSuccess = 0) THEN
? loPfx.LastErrorText
RELEASE loPfx
RELEASE loPrivKey
RELEASE loCert
RELEASE loChain
CANCEL
ENDIF
? "Private key and certificate chain added to the PFX."
RELEASE loPfx
RELEASE loPrivKey
RELEASE loCert
RELEASE loChain