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

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

问题描述

是否有将 PKCS7 文件转换为 PEM 的 openssl api 函数.我能够使用 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
" ); 
  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天全站免登陆