Sample code for 30+ languages & platforms
Java Requires Chilkat v10.1.2+

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.CertStore;
import com.chilkatsoft.chilkat2.ChilkatException;

public class ChilkatExample {

    public static void main(String[] args) {
        CertStore certStore = new CertStore();

        // On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
        // The argument passed to OpenCurrentUserStore is ignored.
        try {
            certStore.openCurrentUserStore(false);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        int numCerts = certStore.getNumCertificates();
        System.out.println("numCerts = " + numCerts);

        Cert cert = new Cert();
        int i = 0;
        while (i < numCerts) {
            certStore.getCert(i, cert);
            System.out.println(cert.getSubjectDN());
            System.out.println(cert.getSubjectCN());
            System.out.println(cert.getSerialNumber());
            System.out.println("----");
            i = i + 1;
        }

        certStore.closeCertStore();
    }
}