Java Requires Chilkat v10.1.2+
Chilkat2 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
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();
String pfxPath = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
String pfxPassword = "test";
try {
certStore.loadPfxFile(pfxPath, pfxPassword);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
int numCerts = certStore.getNumCertificates();
System.out.println("PFX contains " + numCerts + " certificates");
Cert cert = new Cert();
int i = 0;
while (i < numCerts) {
certStore.getCert(i, cert);
System.out.println(i + ": (Common Name) " + cert.getSubjectCN());
System.out.println(i + ": (Serial Number) " + cert.getSerialNumber());
System.out.println(i + ": (Distinguished Name) " + cert.getSubjectDN());
i = i + 1;
}
}
}