Sample code for 30+ languages & platforms
Ruby

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 Ruby Downloads

Ruby
require 'chilkat'

success = false

certStore = Chilkat::CkCertStore.new()

# 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)
    print certStore.lastErrorText() + "\n";
    exit
end

cert = Chilkat::CkCert.new()

numCerts = certStore.get_NumCertificates()
i = 0

while (i < numCerts)
    # Load the cert object with the Nth certificate.
    certStore.GetCert(i,cert)
    print i.to_s() + ": " + cert.subjectCN() + "\n";
    i = i + 1
end