本文介绍了如何在Java中将byte []类型转换为证书类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 byte []
的证书数据,我想将此 byte []
类型更改为证书
类型。我该如何实现呢?
I've a byte[]
of certificate data and I want to change this byte[]
type to Certificate
type. How can I achieve this?
现在我使用了 CertificateFactory.generateCertificate(InputStream inStream)
。
byte[] csr = getCSR(cn, ou, org, loc, state, country,email);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bais = new ByteArrayInputStream(csr);
Certificate certificate = cf.generateCertificate(bais);
但发生错误证书证书= cf.generateCertificate(bais);
错误: java.security.cert.CertificateParsingException:java.io.IOException:ObjectIdentifier()-数据不是对象ID(标签= 49)
为什么会发生此错误?这段代码有什么问题?请给我解释一下。谢谢。
Why this error occurred? What wrong in this code? Please explain me. Thanks.
推荐答案
您可以使用生成证书。
You can use CertificateFactory.generateCertificate(InputStream inStream)
to generate a Certificate.
下面是生成X509证书的示例:
Here is an example which generates an X509 Certificate:
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate certificate = cf.generateCertificate(new ByteArrayInputStream(buf));
这篇关于如何在Java中将byte []类型转换为证书类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!