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
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
