从JAVA中的PKCS#7文件中提取原始证书 [英] Extract raw certificate from PKCS#7 file in JAVA

查看:419
本文介绍了从JAVA中的PKCS#7文件中提取原始证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现此openssl命令执行的功能,但要以Java编程方式实现:

I would like to achieve the same what this openssl command performs, but programmatically in Java:

openssl pkcs7 -in toBeExported.p7c -inform DER -out certificate.pem -print_certs 

这意味着我拥有DER格式的公共密钥证书(PKCS#7证书),并且我想将其中包含的原始证书提取到Base64文件中.有办法吗?

which means that I have a public key certificate (PKCS #7 Certificate) in DER format and I want to extract the raw certificate contained there to a Base64 file. Is there a way to do this?

推荐答案

类似

FileInputStream is = new FileInputStream( "cert.pkcs7" );
CertificateFactory cf = CertificateFactory.getInstance( "X.509" );
Iterator i = cf.generateCertificates( is ).iterator();
while ( i.hasNext() ) 
{
   Certificate c = (Certificate)i.next();
   // TODO encode c as Base64...
}

应使用PKCS#7编码的证书.

should work with PKCS#7 encoded certificates.

干杯

这篇关于从JAVA中的PKCS#7文件中提取原始证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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