title: Openssl RSA Key generation
body: <p>I have a client which talks to a server and communication is encrypted using RSA and AES combination. The RSA key pair which I had generated was without passphrase. So, to make it secure I recently added the passphrase. Every thing works fine server side, but the Private key generated by PHP doesn't contain encryption info, due to which I can't load it client side. Following is the php code:</p>
  
  <pre><code>    $passphrase = 'Hello World';
  
      $config = array ("digest_alg" =&gt; "sha256","private_key_bits" =&gt; 2048,"private_key_type" =&gt; OPENSSL_KEYTYPE_RSA );
      // Create the private and public key
      $res = openssl_pkey_new ( $config );
      /* Extract the private key from $res to $privKey */
      openssl_pkey_export ( $res, $priv_key, $passphrase );
      /* Extract the public key from $res to $pubKey */
      $pub_key = openssl_pkey_get_details ( $res );
      $pub_key = $pub_key["key"];
      $pkey_pair = array ('priv_key' =&gt; $priv_key,'pub_key' =&gt; $pub_key );
      var_dump($pkey_pair);
  </code></pre>
  
  <p>You can try it on <a href="http://phpfiddle.org/" rel="nofollow">http://phpfiddle.org/</a> there is no enryption info, as if it is assuming that, since it works server side!</p>
  
  <p>My client side code works only when no passphrase is used in RSA key generation.</p>
  
  <pre><code>try
      {
          Botan::AutoSeeded_RNG rng;
          Botan::DataSource_Memory privKeyMem(privKey);
          Botan::RSA_PrivateKey *rsaKey = dynamic_cast     &lt;Botan::RSA_PrivateKey*&gt; 
         (Botan::PKCS8::load_key(privKeyMem, rng, passphrase.c_str()));
          if(!rsaKey)
          {
               std::cout &lt;&lt; "The loaded key is not a RSA key!\n";
               return false;
          }
          ....
          .....
      }
      catch(...)
      {
          cout&lt;&lt;"Exception: could not load private key";
          return false;
      }
  </code></pre>