title: OpenSSL only generates public key
body: <p>This is my first encryption try out. This is my code:</p>
  
  <pre><code>$privateKey = openssl_pkey_new(array(
      'private_key_bits' =&gt; 2048, //size of key
      'private_key_type' =&gt; OPENSSL_KEYTYPE_RSA,
  ));
  
  //save the private key to private.key file. Never share this file with anyone.
  openssl_pkey_export_to_file( $privateKey, 'private.key' );
  
  //generate the public key for the private key
  $a_key = openssl_pkey_get_details( $privateKey );
  //save the public key in public.key file. Send this file to anyone who wants to send you the encrypted data.
  file_put_contents( 'public.key', $a_key['key'] );
  
  //free the private key
  openssl_free_key( $privateKey );
  </code></pre>
  
  <p>I get the following errors;</p>
  
  <blockquote>
    <p>Warning: openssl_pkey_export_to_file(): cannot get key from parameter 1 in C:\xampp\htdocs\PHP\25000.php on line 40</p>
    
    <p>Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP\25000.php on line 43</p>
    
    <p>Warning: openssl_free_key() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP\25000.php on line 48</p>
  </blockquote>
  
  <p>I already searched SO. I found that I have to do following:</p>
  
  <ul>
  <li>Install OpenSSL in XAMPP </li>
  <li>Turn on <strong>PHP</strong> and Apache SSL mods</li>
  </ul>
  
  <p>I am not sure if I have done these and I wonder if that is the reason for my error?</p>