title: How to read a public key from a pem file using BIO from openssl?
body: <p>I'm using openssl library and I want to read a public key from a .pem file with BIO. I tried this, but my rsa variable remains uninitialized :</p>
  
  <pre><code> RSA *rsa = RSA_new();
  
   BIO *keybio = NULL;
  
   keybio = BIO_new(BIO_s_file());
   BIO_read_filename(keybio, "public.pem");
  
   // and also tried this instead of last two lines:
   // keybio = BIO_new_file("public.rem", "r");
  
   rsa = PEM_read_bio_RSA_PUBKEY(keybio, &amp;rsa, NULL, NULL);
  </code></pre>
  
  <p>When I debug my application it shows me something like this:</p>
  
  <pre><code>rsa { padding = ???, n = ??? , ...} 
  rsa-&gt;n &lt;unable to read from memory&gt; and so on for all rsa fields.
  </code></pre>
  
  <p>My file is valid and the key is generated respecting PKCS#1 format. I parsed it with an asn1 parser.</p>