Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openssl and PHP

Tags:

php

openssl

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.

like image 437
Jori Avatar asked May 27 '12 12:05

Jori


Video Answer


1 Answers

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.

like image 138
user5175717 Avatar answered Sep 30 '22 03:09

user5175717