title: OpenSSL won't create private keys?
body: <p>Okay, well, this is my first time working with encryption on a project. I am using my hosting provider for SSL, but I also want to encrypt portions of the database that are sensitive. For this, I was told to use OpenSSL. I am testing it on my localhost (WAMP), and have installed OpenSSL and turned on the PHP and Apache SSL mods. Okay, so i've been following tutorials and, using several suggested methods, have been able to generate the public key and store it as a file. For some reason, I can't seem to generate the private key. I will post two versions of code that i've tried:</p>
  
  <pre><code>// generate private key
  $privateKey = openssl_pkey_new(array(
      'private_key_bits' =&gt; 1024,
      'private_key_type' =&gt; OPENSSL_KEYTYPE_RSA,
  ));
  // write private key to file
  openssl_pkey_export_to_file($privateKey, 'private.key');
  // generate public key from private key
  $publicKey = openssl_pkey_get_details($privateKey);
  // write public key to file
  file_put_contents('public.key', $publicKey['key']);
  // clear key
  echo $privateKey;
  
  ?&gt;
  </code></pre>
  
  <p>This generates a public.key file, but provides me the warnings "openssl_pkey_export_to_file(): cannot get key from parameter 1:" and " openssl_pkey_get_details() expects parameter 1 to be resource, boolean."</p>
  
  <p>I also tried an alternative method:</p>
  
  <pre><code>$config = array(
      "config" =&gt; "E:/wamp/bin/apache/apache2.2.22/conf/openssl.cnf",
      "digest_alg" =&gt; "sha512",
      "private_key_bits" =&gt; 1024,
      "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, $privKey, NULL);
  echo "Private Key: ".$privKey;
  // Extract the public key from $res to $pubKey
  $pubKey = openssl_pkey_get_details($res);
  $pubKey = $pubKey["key"];
  echo "Public Key: ".$pubKey;
  $data = 'plaintext data goes here';
  echo "Data: ".$data;
  // Encrypt the data to $encrypted using the public key
  openssl_public_encrypt($data, $encrypted, $pubKey);
  echo "Encrypted: ".$encrypted;
  // Decrypt the data using the private key and store the results in $decrypted
  openssl_private_decrypt($encrypted, $decrypted, $privKey);
  
  echo "Decrypted: ".$decrypted;
  </code></pre>
  
  <p>This was supposed to echo everything, unfortunately my result was a blank private key, a fine public key, plaintext, and encrypted text, and an error when trying to decrypt: "openssl_private_decrypt(): key parameter is not a valid private key"</p>
  
  <p>Clearly, i'm having a problem with private key creation. I've searched the internet thoroughly and haven't been able to fix it, even though I've implemented simple code that seems to work for everyone else.</p>
  
  <p>Thanks in advance,
  Elie Zeitouni</p>