Is there any OpenSSL function to convert PKCS7 file to PEM(是否有任何 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有任何 OpenSSL 函数可以将 PKCS7 文件转换为 PEM


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01