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

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

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();

        // This only loads the contents of the PFX file into the certStore object.
        // It is not importing the PFX into the Windows certificate stores.
        String pfxPassword = "badssl.com";
        try {
            certStore.loadPfxFile("qa_data/pfx/badssl.com-client.p12", pfxPassword);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Examine each certificate (loaded from the PFX) in this certStore object
        Cert cert = new Cert();
        int numCerts = certStore.getNumCertificates();
        int i = 0;
        while (i < numCerts) {
            certStore.getCert(i, cert);
            System.out.println("hasPrivateKey=" + cert.hasPrivateKey() + ", " + cert.getSubjectCN());
            i = i + 1;
        }
    }
}