title: c++ / RSA convert key
body: <p>I'm trying to encrypt something with RSA.</p>
  
  <p>But my rsa libary doesn't seam to be able to use x509 keys.
  So i tried to convert it to a DER key using openssl.</p>
  
  <p>but i don't really understand how it works. i spotted two classes that seemed ok but i can't figure out how to use them.</p>
  
  <p>the function are :</p>
  
  <p>-i2d_X509</p>
  
  <p>-X509</p>
  
  <p>I did find a piece of code, but i can't understand it :</p>
  
  <pre><code> int len;
   unsigned char *buf, *p;
  
   len = i2d_X509(x, NULL);
  
   buf = OPENSSL_malloc(len);
  
   if (buf == NULL)
        /* error */
  
   p = buf;
  
   i2d_X509(x, &amp;p);
  </code></pre>
  
  <p>If you could help me out it would be great.</p>