I want to encode and decode my data using Laravel PHP-JWT package. which require Private and Public Key in string format.
Therefore, I have created the certificate.pem
by converting .crt to .pem format using below command
x509 -inform DER -outform PEM -in cert.crt -out certificate.pem
As openssl_pkey_get_private and openssl_pkey_get_public accept certificate in .pem format as parameter and Return Positive Key Resources.
Note: Positive Key Resouces is
resource id='588' type='OpenSSL key'
in debugging.
/* Path to certificate */
$path = storage_path('test/certificate.pem');
/* Extract the private key from $res to $privKey */
$privKey = openssl_pkey_get_private($path);
/* Extract the public key from $res to $pubKey */
$pubKey = openssl_pkey_get_public($path);
Query 1: Returning
false
in both$privKey
and$pubKey
Query 2: Will
JWT::encode
accept as a parameter theseKey Resouces
object which is returning from OpenSSL function?
Is there any alternative?
Edit 1: I have OpenSSL enabled in phpinfo.
Edit 2: openssl_error_string output.
$path = storage_path('test/certificate.pem');
$private_key = openssl_pkey_get_private(file_get_contents($path)); // resource id='565' type='OpenSSL key'
$public_key = openssl_pkey_get_public(file_get_contents($path)); // false
$pubkey_error_message = openssl_error_string(); // "error:0909006C:PEM routines:get_name:no start line"