Sample code for 30+ languages & platforms
Visual FoxPro

Find Certificate by Subject CN (Common Name)

See more Cert Store Examples

Demonstrates how to find a certificate having the specified subject CN.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loCertStore
LOCAL lnReadOnly
LOCAL loJson
LOCAL loCert

lnSuccess = 0

loCertStore = CreateObject('Chilkat.CertStore')

* This opens the Current User certificate store on Windows,
* On MacOS and iOS it opens the default Keychain.
lnReadOnly = 0
lnSuccess = loCertStore.OpenCurrentUserStore(lnReadOnly)
IF (lnSuccess = 0) THEN
    ? loCertStore.LastErrorText
    RELEASE loCertStore
    CANCEL
ENDIF

* Find the certificate having a Subject CN = "Example ABC".
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("CN","Example ABC")

loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCertStore.FindCert(loJson,loCert)
IF (lnSuccess = 1) THEN
    * Show the full distinguished name of the certificate.
    ? "Found: " + loCert.SubjectDN
ELSE
    ? "Not found."
ENDIF

RELEASE loCertStore
RELEASE loJson
RELEASE loCert