Sample code for 30+ languages & platforms
Xbase++

Find Certificate by Subject O (Organization)

See more Cert Store Examples

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

Note: Requires Chilkat v10.1.2 or later.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCertStore
LOCAL nReadOnly
LOCAL oJson
LOCAL cOrganization
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 O = "ICP-Brasil".
oJson := CreateObject("Chilkat.JsonObject")
cOrganization := "ICP-Brasil"
oJson:UpdateString("O", cOrganization)

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()