title: PHP - Decrypt - OpenSSL
body: <p>The encryption is done correctly, but when to use <code>openssl_get_privatekey</code> and save in <code>$key_resource</code>, this has a null value, so it throws the error: <code>openssl_private_decrypt(): key parameter is not a valid private key in ...</code></p>
  
  <pre><code>    function encriptarDatos($datos){
          $fp=fopen("public.key","r"); 
          $pub_key=fread($fp,8192); 
          fclose($fp); 
          $key_resource = openssl_get_publickey($pub_key); 
  
          openssl_public_encrypt($datos,$encriptado,$key_resource ); 
          /*uses the already existing key resource*/ 
          return(base64_encode($encriptado));
      }
  
  function desencriptarDatos($datos){
          $fp=fopen("private.key","r"); 
          $priv_key=fread($fp,8192); 
          fclose($fp); 
          echo "priv_key: $priv_key &lt;br/&gt;&lt;br/&gt;";
          $key_resource = openssl_get_privatekey($priv_key);
          echo "key_resourse: $key_resource";
  
          openssl_private_decrypt($datos,$desencriptado,$key_resource); 
          /*uses the already existing key resource*/ 
          return(base64_encode($desencriptado));
      }
  </code></pre>
  
  <p>Then I changed it:</p>
  
  <pre><code>        $fp=fopen("private.key","r"); 
          $priv_key=fread($fp,8192); 
          fclose($fp); 
  
          openssl_private_decrypt($datos, $desencriptado, openssl_pkey_get_private($priv_key, "phrase"));
          /*uses the already existing key resource*/ 
          return(base64_encode($desencriptado));
  </code></pre>
  
  <p>but the result is also null</p>