How to instantiate javax.security.X509Certficate object from a p12 certificate (contains certificate + private key)

二次信任 提交于 2019-12-07 06:57:51

问题


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:


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


来源:https://stackoverflow.com/questions/4030585/how-to-instantiate-javax-security-x509certficate-object-from-a-p12-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!