Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCertStore
LOCAL nReadOnly
LOCAL oJson
LOCAL oCert

nSuccess := 0

oCertStore := CreateObject("Chilkat.CertStore")

//  This opens the Current User certificate store on Windows,
//  On MacOS and iOS it opens the default Keychain.
nReadOnly := 0
nSuccess := oCertStore:OpenCurrentUserStore(nReadOnly)
IF (nSuccess == 0)
    ? oCertStore:LastErrorText
    oCertStore:destroy()
    RETURN
ENDIF

//  Find the certificate having a Subject CN = "Example ABC".
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("CN", "Example ABC")

oCert := CreateObject("Chilkat.Cert")
nSuccess := oCertStore:FindCert(oJson, oCert)
IF (nSuccess == 1)
    //  Show the full distinguished name of the certificate.
    ? "Found: " + oCert:SubjectDN
ELSE
    ? "Not found."
ENDIF

oCertStore:destroy()
oJson:destroy()
oCert:destroy()