How to instantiate javax.security.X509Certficate o

2019-05-01 12:15发布

X509Certificate is only instantiatable using the contents of a certificate (.cer file). How to instantiate this object using a .p12 file that contains both the certificate and the private key?

1条回答
叛逆
2楼-- · 2019-05-01 12:42

Here is what you need:

InputStream inStream = new FileInputStream("c:/certificate.p12");

KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(inStream, "password".toCharArray());  

String alias = ks.aliases().nextElement();
certificate = (X509Certificate) ks.getCertificate(alias);
查看更多
登录 后发表回答