title: OpenSSL's rsautl cannot load public key created with PEM_write_RSAPublicKey
body: <p>I've generated a public key using openssl</p>
  
  <pre><code>BIGNUM* e = BN_new();
  BN_set_word(e, 17);
  RSA* rsa = RSA_new();
  if(!RSA_generate_key_ex(rsa, 2048, e, NULL)) {
      LOG(security, debug) &lt;&lt; "failed to generate private key";
  }
  </code></pre>
  
  <p>And these are written to files:</p>
  
  <pre><code>FILE* pubwriter = fopen("key.pub", "wb");
  int err = PEM_write_RSAPublicKey(pubwriter, key);
  if(!err) {
      throw new std::runtime_error("Failed to store public key");
  }
  FILE* privwriter = fopen("key.priv", "wb");
  std::string password = "password";
  err = PEM_write_RSAPrivateKey(privwriter, key, EVP_des_ede3_cbc(),
                                  (unsigned char*)password.c_str(),
                                  password.size(), NULL, NULL);
  </code></pre>
  
  <p>And they seem to be stored correctly, key.pub then contains something like</p>
  
  <pre><code>-----BEGIN RSA PUBLIC KEY-----
  MIIBCAKCAQEA0rG1b0g3NIsDT8HkzgTx8BUI9LhueWbH1NuAvIh9qTF57GzEXuTu
  jxBcuSzWXlR83ci4oITp7VqV6KLVoJryf8orGXBVi9A73JYOQVB6FEzARKym/g8E
  fSEwSmdQ4NfiTESwOCtIextdu3x8pANSYDyyqdiWsSHy0SiZmkbvdVYomIBJZOV9
  jhb3mkmD0WUYie9AXziTbli97YqDiN168kMI+7ePpbNJFSVSIUkPPocSgvgcAux/
  HuDqftzBgyAF3NGb3AAra1A8T7yPOqLyYyXdIJmF+/Svk5PdMbZVE/U76cjBThch
  Q9AiLo25hOjkmtuEQubCuwrUDleblr93aQIBEQ==
  -----END RSA PUBLIC KEY-----
  </code></pre>
  
  <p>Now I want to try these to make sure I haven't got anything wrong but it wont' load:</p>
  
  <pre><code>$ openssl rsautl -encrypt -inkey key.pub -pubin -in data.txt -out enc.txt
  unable to load Public Key
  </code></pre>
  
  <p>What am I missing?</p>