java读取X509拓展,通过Java API打开x509证书存储

I am trying to show the list of certificates from the Client Certificate store in JSP.

In .Net there is an option to show the list of certificates with the following code...

X509Store xStore = new X509Store(...);

xStore.Open(...); // This will open the list of certicates in open dialog box.

Is there any similar functionality to get this information in Java?

解决方案

You can open a JKS store using the default JDK classes, to open a pkcs12 file or the likes you need a library like bouncycastle. For example:

KeyStore keystore = KeyStore.getInstance("PKCS12", "BC");

Then load the actual keystore:

keystore.load(inputStream, password);

Note that an empty password is handled differently by bouncycastle or jdk (one requires an empty string the other null iirc). Once you have a keystore instance, you can get the certificates easily by looping over the aliases and checking the types:

Enumeration aliases = keystore.aliases();

while (aliases.hasMoreElements()) {

String alias = aliases.nextElement();

if (store.entryInstanceOf(alias, KeyStore.TrustedCertificateEntry.class))

certificates.put(alias, (X509Certificate) store.getCertificate(alias));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值