如何获取PEM编码的X509证书作为C ++字符串使用openssl? [英] How to get PEM encoded X509 certificate as C++ string using openssl?

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

问题描述

我有一个带有自签名证书的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

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

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