Sample code for 30+ languages & platforms
Visual FoxPro

Load PEM and List Certificates

Demonstrates how to load a PEM containing certificates and accesses each individual certificate.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loPem
LOCAL i
LOCAL lnNumCerts
LOCAL loCert

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

lnSuccess = 0

loPem = CreateObject('Chilkat.Pem')

* Load the .p7b from a file.
lnSuccess = loPem.LoadPemFile("/Users/chilkat/testData/p7b/cacert_mozilla.pem")
IF (lnSuccess <> 1) THEN
    ? loPem.LastErrorText
    RELEASE loPem
    CANCEL
ENDIF

lnNumCerts = loPem.NumCerts
IF (lnNumCerts = 0) THEN
    ? ("Error: Expected the PEM to contain certificates.")
    RELEASE loPem
    CANCEL
ENDIF

* Access each certificate and show the Subject CN (Common Name)
FOR i = 1 TO lnNumCerts
    loCert = loPem.GetCert(i - 1)
    ? STR(i) + ": " + loCert.SubjectCN
    RELEASE loCert
NEXT

RELEASE loPem