OpenSSL, openssl_pkey_get_private

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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

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



Re: OpenSSL, openssl_pkey_get_private

Quoted text here. Click to load it

Nevermind, I found it. 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",

It may be that I'm using a slightly older version of OpenSSL, but this
fixed it for me.

Site Timeline