Sample code for 30+ languages & platforms
Java

List Certificates in the Current User Certificate Store (Windows Only)

See more Certificates Examples

This is a Windows-only example to list the certificates in the current-user certificate store (located in the Windows Registry).

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    // This is a Windows-only example because it lists the certificates
    // stored in the Windows Current User Certificate Store located in the
    // Windows Registry.

    CkCertStore certStore = new CkCertStore();

    boolean readOnly = true;
    success = certStore.OpenCurrentUserStore(readOnly);
    if (success == false) {
        System.out.println(certStore.lastErrorText());
        return;
        }

    CkCert cert = new CkCert();
    int numCerts = certStore.get_NumCertificates();
    int i = 0;
    while (i < numCerts) {
        certStore.GetCert(i,cert);
        System.out.println("DN = " + cert.subjectDN());
        System.out.println("Email = " + cert.subjectE());
        i = i+1;
        }
  }
}