title: How to create a RSA public key from a unsigned char * modulus and exponent 65537(RSA_F4)
body: <p>I'm trying generate a rsa public key from a modulus type char[], and I now the exponent is RSA_F4(65537);
  But when I'm trying generate my public key using this values for "n" and "e", the RSA_public_encrypt, return -1;</p>
  
  <p>Thanks!</p>
  
  <p>My code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;crypt.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;openssl/rsa.h&gt;
  #include &lt;openssl/aes.h&gt;
  #include &lt;openssl/opensslconf.h&gt;
  #include &lt;openssl/engine.h&gt;
  #include &lt;openssl/pem.h&gt;
  #include &lt;openssl/rc4.h&gt;
  
  using namespace std;
  int main(void)
  {
  
  //modulus in format char hex;
  char key[] = "C0E7FC730EB5CF85B040EC25DAEF288912641889AD651B3707CFED9FC5A1D3F6C40062AD46E3B3C3E21D4E71CC4800C80226D453242AEB2F86D748B41DDF35FD";
  
      char palavra[] = "teste";
      char crip[512];
      int ret;
      RSA * pubkey = RSA_new();
      BIGNUM * modul = BN_new();
      BIGNUM * expon = BN_new();
  
      BN_hex2bn(&amp;modul, (const char *) key);
      BN_hex2bn(&amp;expon, "010001");
  
      cout &lt;&lt; "N KEY: " &lt;&lt; BN_bn2hex(modul) &lt;&lt; endl;
      cout &lt;&lt; "E KEY: " &lt;&lt; BN_bn2hex(expon) &lt;&lt; endl;
  
      pubkey-&gt;n = modul;
      pubkey-&gt;e = expon;
  
      cout &lt;&lt; "N PUB KEY: " &lt;&lt; BN_bn2hex(pubkey-&gt;n) &lt;&lt; endl;
      cout &lt;&lt; "E PUB KEY: " &lt;&lt; BN_bn2hex(pubkey-&gt;e) &lt;&lt; endl;
  
      if (RSA_public_encrypt(strlen((const char *) palavra), (const unsigned char *) palavra, (unsigned char *) crip, pubkey, RSA_PKCS1_PADDING ))
      {
          printf("ERRO encrypt\n");
      }
      else
      {
          printf("SUC encrypt\n");
      }
  return 0;
  }
  </code></pre>