OpenSSL, openssl_pkey_get_private [message #175257] |
Tue, 30 August 2011 08:26 |
jwcarlton
Messages: 76 Registered: December 2010
Karma: 0
|
Member |
|
|
This is a new one for me, so bear with me.
I'm following a tutorial for encrypting data. I used the following to
generate a public and private key on a Linux Redhat 4 system:
openssl genrsa -des3 -out private_key.pem 2056
openssl rsa -pubout -in private_key.pem -out public_key.pem
Now, I need to get those keys, and I'm using:
$public_key = openssl_pkey_get_public('file://public_key.pem');
$private_key = openssl_pkey_get_private('file://private_key.pem', '[my
password]');
I'm returning false, though, and I'm guessing that it's because of the
"file://" (which looks like what you'd use on a Windows server)? I
tried file:///, though, and it had no impact.
I've tried every variation I could think of, but I'm still getting
nothing.
I DO have OpenSSL turned on when I compiled Apache (I triple-checked).
I'm not seeing any references to it in php.ini, but I do have the
following disabled:
show_source, system, shell_exec, passthru, exec, phpinfo, popen,
proc_open, allow_url_fopen, ini_set
Would any of those affect it?
If not, can you guys suggest how I should be retrieving the key
correctly?
TIA,
Jason
|
|
|
Re: OpenSSL, openssl_pkey_get_private [message #175258 is a reply to message #175257] |
Tue, 30 August 2011 08:49 |
jwcarlton
Messages: 76 Registered: December 2010
Karma: 0
|
Member |
|
|
On Aug 30, 4:26 am, jwcarlton <jwcarl...@gmail.com> wrote:
> This is a new one for me, so bear with me.
>
> I'm following a tutorial for encrypting data. I used the following to
> generate a public and private key on a Linux Redhat 4 system:
>
> openssl genrsa -des3 -out private_key.pem 2056
> openssl rsa -pubout -in private_key.pem -out public_key.pem
>
> Now, I need to get those keys, and I'm using:
>
> $public_key = openssl_pkey_get_public('file://public_key.pem');
> $private_key = openssl_pkey_get_private('file://private_key.pem', '[my
> password]');
>
> I'm returning false, though, and I'm guessing that it's because of the
> "file://" (which looks like what you'd use on a Windows server)? I
> tried file:///, though, and it had no impact.
>
> I've tried every variation I could think of, but I'm still getting
> nothing.
>
> I DO have OpenSSL turned on when I compiled Apache (I triple-checked).
> I'm not seeing any references to it in php.ini, but I do have the
> following disabled:
>
> show_source, system, shell_exec, passthru, exec, phpinfo, popen,
> proc_open, allow_url_fopen, ini_set
>
> Would any of those affect it?
>
> If not, can you guys suggest how I should be retrieving the key
> correctly?
>
> TIA,
>
> Jason
Nevermind, I found it. PHP.net doesn't make it too clear that you have
to send the data for opensl_pkey_get_private() as an array:
$private_key = openssl_pkey_get_private(array("file://$priv_key",
$passphrase))
It may be that I'm using a slightly older version of OpenSSL, but this
fixed it for me.
|
|
|