Bouncycastle:X509CertificateHolder 到 X509Certificate?

发布于 2024-11-16 02:44:13 字数 214 浏览 3 评论 0原文

在 r146 之前的版本中,可以直接创建 X509Certificate 对象。 现在该 API 已弃用,新 API 仅提供一个 X509CertificateHolder 对象。

我找不到将 X509CertificateHolder 转换为 X509Certificate 的方法。

这怎么能做到呢?

In versions prior to r146 it was possible to create X509Certificate objects directly.
Now that API is deprecated and the new one only deliveres a X509CertificateHolder object.

I cannot find a way to transform a X509CertificateHolder to X509Certificate.

How can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

策马西风 2024-11-23 02:44:13

我会回答我自己的问题,但不会删除它,以防其他人遇到同样的问题:

return new JcaX509CertificateConverter().getCertificate(certificateHolder);

对于属性证书:

return new X509V2AttributeCertificate(attributeCertificateHolder.getEncoded());

不好,因为它是编码和解码,但它有效。

I will answer to my own questions, but not delete it, in case someone else got the same problems:

return new JcaX509CertificateConverter().getCertificate(certificateHolder);

And for attribute certificates:

return new X509V2AttributeCertificate(attributeCertificateHolder.getEncoded());

Not nice, as it is encoding and decoding, but it works.

鯉魚旗 2024-11-23 02:44:13

另一种选择是这个:)

CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(certificateHolder.getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);

Another option is this one :)

CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(certificateHolder.getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
你对谁都笑 2024-11-23 02:44:13

可以将 X509CertificateHolder 获取到 X509CertificatetoString。 (代码第一句无关紧要)

X509CertificateHolder selfSignedCertificate = CertificateUtils.selfSignCertificate(certificationRequest, keyPair.getPrivate());
byte[] content = selfSignedCertificate.getEncoded();
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(content));
logger.debug("cert: {}", cert.toString());

........

This is an possibility to get the X509CertificateHolder to X509Certificate and toString. (first sentence of the code is irrelevant)

X509CertificateHolder selfSignedCertificate = CertificateUtils.selfSignCertificate(certificationRequest, keyPair.getPrivate());
byte[] content = selfSignedCertificate.getEncoded();
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(content));
logger.debug("cert: {}", cert.toString());

........

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文