本文介绍了如何通过PEM证书作为i2d_X509的第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过创建自签名证书:

  OpenSSL的REQ -new -x509 -key privkey.pem退房手续cert.pem -days 1095

我如何通过cert.pem到i2d_X509?
我需要的是这样的:

  LEN = i2d_X509(,&AMP\\ cert.pem。BUF);

但我在PEM文件证书。

下面是我的code:(我以前在 https://开头www.openssl.org/docs/crypto/d2i_X509.html )

 的#include<的OpenSSL / x509.h>
#包括LT&;&stdio.h中GT;INT主要(无效)
{
    INT LEN,我;
    无符号字符* BUF;    BUF = NULL;
    LEN = i2d_X509((X509 *)。\\ cert.pem,&放大器; BUF);    如果(LEN℃,){
        输出(错误的len℃的);
        返回-1;
     }    的printf(BUF:);
    对于(i = 0; I< LEN,我++)
        的printf(为0x%02X,*(BUF + I));    返回0;
}


解决方案

You don't/can't. You need to read the certificate with PEM_read_bio_X509. PEM_read_bio_X509 returns an X509*. Then you can pass it to i2d_X509.

Be sure to call X509_free on the pointer when done with it.

Or, do as Philippe suggests - convert it to ASN.1/DER and then use it with d2i_X509_fp.

Also see the OpenSSL man pages on the PEM Read/Write functions.

这篇关于如何通过PEM证书作为i2d_X509的第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:16