title: Open SSL extract certificate from X509 structure into char array
body: <p>I am using OpenSSL to construct my own self signed certificate which I have in an X509 structure. I wan't to extract the certificate data out of the X509 structure into a char array.</p>
  
  <p>I am aware of the following macro:</p>
  
  <pre><code>PEM_Write_X509(file *, certificate *)
  </code></pre>
  
  <p>This will output to a file something like:</p>
  
  <pre><code>-----BEGIN CERTIFICATE------
  DATAHERE
  -----END CERTIFICATE-----
  </code></pre>
  
  <p>What I really want is just the "DATAHERE" part directly into a char array. There are a baffling number of macros for doing various things, but I haven't stumbled across one that does what I'm after. Is there anything suitable that I haven't found?</p>