title: Load X509 Certificate From MySQL BLOB
body: <p>I stored a x509 Certificate as BLOB in MySQL. I want to import that certificate now into c++ using the openssl lib.</p>
  
  <p>i figured to use this function</p>
  
  <pre><code>X509 *parsedCert = d2i_X509_bio(bio_in, 0);
  </code></pre>
  
  <p>Problem is i need a Pointer to a BIO struct. Because i did not store the certificate into a file, i can only use</p>
  
  <pre><code>BIO* BIO_new_mem_buf( void* buf, int length);
  </code></pre>
  
  <p>to retreive my BIO Pointer. Because MySQL gives me the BLOB stored certificate as istream, i tried</p>
  
  <pre><code>istream* cert = res-&gt;getBlob("cert");
  string certs = streamToString(*cert);
  BIO *bio_in = BIO_new_mem_buf( const_cast&lt;char*&gt;(certs.c_str()), -1 );
  X509 *parsedCert = d2i_X509_bio(bio_in, 0);
  </code></pre>
  
  <p>Unfortunately parsedCert is a Nullpointer. I get the following SSL Errors:</p>
  
  <pre><code>SSL ERROR: error:0D06B08E:asn1 encoding routines:func(107):reason(142)
  </code></pre>
  
  <p>My Question is: Is there a way to directly load a x509 certificate from istream to OpenSSL X509 structure?</p>