Java解析X509证书代码

原创
2019/08/20 17:28
阅读数 4.7K

通过PKCS12格式的证书库文件获取证书对象

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);
System.out.println(certificate .getNotAfter());

通过pem文件获取证书对象

CertificateFactory fact = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) fact.generateCertificate(new FileInputStream ("conf/server.crt"));

获取证书的公钥

PublicKey pk = certificate.getPublicKey();
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部