phpopensslprivate-keyphp-openssl

ERROR - Unable to load signing key. Can't sign my text with my Private Key - PHP


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 :

(Sorry can't display images lol)


Solution

  • 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();
    }