0

I can't instanciate my $pemkey whit a relative path in my php code. When I try to instanciate my key with openssl_pkey_get_private the program doesn't find it.

Here is my code :

$pemkey = openssl_pkey_get_private("file:///licensePrivateKey.pem");
if (! $pemkey ){
    echo "ERROR - Unable to load signing key.";
    die();
}

And here are my files :

  • folder
    • download_file.php
    • licensePrivateKey.pem

(Sorry can't display images lol)

Akashiro
  • 11
  • 2

2 Answers2

0

Check this note on PHP manual website https://www.php.net/manual/en/function.openssl-pkey-get-private.php#114998
So you only have to concatenate "file://" with an existing path string in every case

This looks like an absolute path /licensePrivateKey.pem
You are using windows or unix system?

vmar
  • 13
  • 3
  • I'm using a Windows system. and the path is supposed to be realtive, so did I do smth wrong ? – Akashiro Dec 02 '22 at 14:50
  • Putting 2 slashes only also shows the error message – Akashiro Dec 02 '22 at 14:56
  • check for errors var_dump(openssl_error_string()); for more info visit [link](https://stackoverflow.com/questions/52593674/openssl-pkey-get-private-returning-false) – vmar Dec 02 '22 at 15:13
0

I solved the error by creating an absolute path with dirname(__FILE__) and and my file name. Here's the code :

$path = dirname(__FILE__);
$key = "licensePrivateKey.pem";
$pemkey = openssl_pkey_get_private("file://".$path."/".$key);
if (! $pemkey ){
    echo "ERROR - Unable to load signing key.";
    var_dump(openssl_error_string());
    die();
}
Akashiro
  • 11
  • 2