如何使用openssl将PEM编码的X509证书作为C++字符串获取?

2024-08-14C/C++开发问题
37

本文介绍了如何使用openssl将PEM编码的X509证书作为C++字符串获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个带有自签名证书的 openssl X509 结构.我需要从此结构中获取 PEM 格式的 C++ 字符串.我需要使用哪些 openssl API 来实现这一目标?

I have a openssl X509 structure with a self signed certificate. I need to get a PEM formatted C++ string from this structure. What are the openssl APIs that I need to use to achieve this?

我尝试遵循 https 上的示例程序://www.codeblog.org/gonzui/markup/openssl-0.9.8a/demos/x509/mkcert.c.该程序展示了一种将 PEM 格式的证书写入文件的方法.如果没有其他方法,我可以将此文件的内容读入 C++ 字符串.

I tried following the example program at https://www.codeblog.org/gonzui/markup/openssl-0.9.8a/demos/x509/mkcert.c. This program shows a way to write the certificate in PEM format to a file. I can read the contents of this file into a C++ string if there is no other way to do it.

推荐答案

查看 openssl x509 命令的源码,看看它是如何执行读取 DER 编码文件并写入 PEM 的操作的 - 即:

look at the source of the openssl x509 command and see how it does the operation to read a DER encoded file and writes a PEM one - ie:

openssl x509 -in mycert.der -inform DER -out mycert.pem

cli utils 的代码很容易理解

The code of the cli utils is pretty easy to follow

这篇关于如何使用openssl将PEM编码的X509证书作为C++字符串获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6