是否有任何OpenSSL函数将PKCS7文件转换为PEM [英] Is there any OpenSSL function to convert PKCS7 file to PEM

查看:344
本文介绍了是否有任何OpenSSL函数将PKCS7文件转换为PEM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何openssl api函数将PKCS7文件转换为PEM.我能够使用PKCS12_parse()函数将PKCS12文件转换为PEM,该函数将返回给定密码的密钥和证书. pkcs7没有类似的功能.

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.

我的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

如何在C程序中执行此操作?我可以将其读取为这样的PKCS7结构

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)); 
}

其中p7是指向pkcs7结构的指针,而fp是指向PEM文件的文件指针

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

这篇关于是否有任何OpenSSL函数将PKCS7文件转换为PEM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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