Visual FoxPro
Visual FoxPro
Iterate Keys and Certs in PEM
See more PEM Examples
Demonstrates how to access each of the private keys and certs contained within a PEM.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPem
LOCAL lcPassword
LOCAL lcPemContent
LOCAL lnNumPrivateKeys
LOCAL i
LOCAL loPrivKey
LOCAL loCert
LOCAL lnNumCerts
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loPem = CreateObject('Chilkat.Pem')
* Load the PEM from a file.
* If the PEM is encrypted, provide a password. Otherwise pass an empty string for the password.
lcPassword = "myPassword"
lnSuccess = loPem.LoadPemFile("../myPemFiles/myPem.pem",lcPassword)
IF (lnSuccess = 0) THEN
? loPem.LastErrorText
RELEASE loPem
CANCEL
ENDIF
* Note: If the app already has the PEM pre-loaded in a string variable, then load it
* by calling LoadPem instead.
lcPemContent = "... the PEM contents ..."
lnSuccess = loPem.LoadPem(lcPemContent,lcPassword)
* Check for success as before..
* Iterate over the private keys.
lnNumPrivateKeys = loPem.NumPrivateKeys
i = 0
loPrivKey = CreateObject('Chilkat.PrivateKey')
DO WHILE i < lnNumPrivateKeys
loPem.PrivateKeyAt(i,loPrivKey)
? "Private Key " + STR(i) + " is " + STR(loPrivKey.BitLength) + " in length"
i = i + 1
ENDDO
* Iterate over the certificates.
loCert = CreateObject('Chilkat.Cert')
lnNumCerts = loPem.NumCerts
i = 0
DO WHILE i < lnNumCerts
loPem.CertAt(i,loCert)
? "Certificate " + STR(i) + " : " + loCert.SubjectDN
i = i + 1
ENDDO
RELEASE loPem
RELEASE loPrivKey
RELEASE loCert