将OpenSSL x509数据转换为std :: string

时间:2016-10-11 00:05:15

标签: c++ openssl x509certificate x509 pem

我想在C ++中将X509数据转换为字符串格式。我尝试了以下方法,但我只能打印一行而不是整个数据。有人可以帮帮我吗?任何帮助都感激不尽。请找到示例代码:

  BIO *bio; string issuer;
  bio = BIO_new(BIO_s_mem());
  if(bio == NULL) {
       throw f5util::Exception("BIO_new failed..");
   }

   // my_Issuer is actually X509 *. 

   if(PEM_write_bio_X509(bio, my_Issuer) == 0) {
        BIO_free(bio);
        throw f5util::Exception("PEM_write_bio_x509() failed..");
    }
    issuer.resize(bio->num_write);
    int bio_len = BIO_read(bio, &issuer[0], bio->num_write);
    issuer.resize(bio_len);

     // here I tried to print the string output and I got only first line 
    //     i.e. "---------BEGIN CERTIFICATE-----------"

    BIO_free(bio);

我也欢迎任何替代方法/建议。

0 个答案:

没有答案