简体   繁体   English

将X509证书保存到文件中

[英]Save X509 certificate to a file

I am working on a HTTPS client and I managed to establish a secure connection and get the X509 certificate using: 我正在使用HTTPS客户端,我设法建立安全连接并使用以下方式获取X509证书:
X509 *cert = SSL_get_certificate(ssl); (ssl is SSL*). (ssl是SSL *)。

How do I save the certificate to a file? 如何将证书保存到文件? Also, I need to get "Subject DN" and "Issuer DN" fields from the certificate. 另外,我需要从证书中获取“Subject DN”和“Issuer DN”字段。

-- How do I save the certificate to a file? - 如何将证书保存到文件?

#include <openssl/pem.h>
int PEM_write_X509(FILE *fp, X509 *x);

-- Also, I need to get "Subject DN" and "Issuer DN" fields from the certificate. - 此外,我需要从证书中获取“主题DN”和“颁发者DN”字段。

#include <openssl/x509.h>
X509_NAME *     X509_get_issuer_name(X509 *a);
X509_NAME *     X509_get_subject_name(X509 *a); 

To encode the certificate into a file you can use this OpenSSL function: 要将证书编码为文件,您可以使用此OpenSSL函数:

int i2d_X509_fp(X509 *x, FILE *fp);

It encodes the X509 structure pointed by x into file using the DER encoding. 它使用DER编码将x指向的X509结构编码到文件中。 More details on the OpenSSL API reference . 有关OpenSSL API参考的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM