java pkcs7 pem,是否有任何OpenSSL函数将PKCS7文件转换为PEM

博客内容讲述了如何在C程序中使用OpenSSL库将PKCS7文件转换为PEM格式。作者通过研究找到了一个方法,即在解析PKCS7结构后,使用PEM_write_X509函数将证书写入PEM文件。这个过程类似于使用PKCS12_parse函数转换PKCS12文件。
摘要由CSDN通过智能技术生成

Is there any openssl api function to convert PKCS7 file to PEM. I am able to convert a PKCS12 file to PEM using PKCS12_parse() function which returns key and certificate given the password. There is no similar function for pkcs7.

My pkcs7 input has just the certificate in binary format. I am able to do the conversion using command

openssl pkcs7 -inform DER -in input.p7b -printcerts -text

How do I do this in a C program? I am able to read it to a PKCS7 structure like this

FILE* fp;

if (!(fp = fopen("ca.p7b", "rb"))) {

fprintf(stderr, "Error reading input pkcs7 file\n" );

exit(1);

}

PKCS7 *p7;

p7 = d2i_PKCS7_fp(cafp, NULL);

解决方案

After some googling I am able to do that.

if(p7->d.sign->cert != NULL){

PEM_write_X509(fp, sk_X509_value(p7->d.sign->cert, 0));

}

where p7 is a pointer to pkcs7 struct and fp is the file pointer to PEM file

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值