Sample code for 30+ languages & platforms
Go

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Go Downloads

Go
    success := false

    certStore := chilkat.NewCertStore()

    // This opens the Current User certificate store on Windows,
    // On MacOS and iOS it opens the default Keychain.
    readOnly := false
    success = certStore.OpenCurrentUserStore(readOnly)
    if success == false {
        fmt.Println(certStore.LastErrorText())
        certStore.DisposeCertStore()
        return
    }

    cert := chilkat.NewCert()

    numCerts := certStore.NumCertificates()
    i := 0

    for (i < numCerts) {
        // Load the cert object with the Nth certificate.
        certStore.GetCert(i,cert)
        fmt.Println(i, ": ", cert.SubjectCN())
        i = i + 1
    }


    certStore.DisposeCertStore()
    cert.DisposeCert()