Php – Openssl and PHP

opensslPHP

Im trying to load a private key generated by the openssl cli tool with PHP.
I used the following command and PHP code:

openssl genrsa -des3 4096 -out private.key

if (!($key = openssl_pkey_get_private("file://private.key", "password")));
{
      return false;
}

I'm sure the password is correct and the file is also PEM formatted, but it keeps returning false. What am I doing wrong?

Thanks in advance,
Jori.

Best Answer

Please note that file://path/to/file.pem in documentation means file protocol + file path. In UNIX like OS, that is something like file:///rsa_private_key.pem. There is THREE slashes in the path string, not TWO. And file:// cannot be omitted.