Sample code for 30+ languages & platforms
Ruby

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

success = false

certStore = Chilkat::CkCertStore.new()

# On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
# The argument passed to OpenCurrentUserStore is ignored.
success = certStore.OpenCurrentUserStore(false)
if (success == false)
    print certStore.lastErrorText() + "\n";
    exit
end

numCerts = certStore.get_NumCertificates()
print "numCerts = " + numCerts.to_s() + "\n";

cert = Chilkat::CkCert.new()
i = 0
while i < numCerts
    certStore.GetCert(i,cert)
    print cert.subjectDN() + "\n";
    print cert.subjectCN() + "\n";
    print cert.serialNumber() + "\n";
    print "----" + "\n";
    i = i + 1
end

certStore.CloseCertStore()