从byte []生成X509Certificate? [英] Generate X509Certificate from byte[]?

查看:483
本文介绍了从byte []生成X509Certificate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从byte []生成java.security.cert.X509Certificate?

Is there a possibility to generate an java.security.cert.X509Certificate from an byte[]?

推荐答案

当然。

证书对象可以由 CertificateFactory - 特别是配置为创建X509证书的一个。这可以像这样创建:

The certificate objects can be created by an instance of CertificateFactory - in particular, one configured to create X509 certificates. This can be created like so:

CertificateFactory certFactory = CertificateFactory.getInstance("X.509");

然后你需要传递一个包含证书字节的InputStream。这可以通过将字节数组包装在 ByteArrayInputStream <中来实现。 / a>:

Then you need to pass it an InputStream containing the bytes of the certificate. This can be achieved by wrapping your byte array in a ByteArrayInputStream:

InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);

这篇关于从byte []生成X509Certificate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆