Sample code for 30+ languages & platforms
Java

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

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;

    CkCertStore certStore = new CkCertStore();

    String pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
    String pfxPassword = "test";
    success = certStore.LoadPfxFile(pfxPath,pfxPassword);
    if (success != true) {
        System.out.println(certStore.lastErrorText());
        return;
        }

    int numCerts = certStore.get_NumCertificates();

    System.out.println("PFX contains " + numCerts + " certificates");

    CkCert cert = new CkCert();
    int i = 0;
    while (i < numCerts) {
        certStore.GetCert(i,cert);

        System.out.println(i + ": (Common Name) " + cert.subjectCN());
        System.out.println(i + ": (Serial Number) " + cert.serialNumber());
        System.out.println(i + ": (Distinguished Name) " + cert.subjectDN());

        i = i+1;
        }
  }
}