Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenSSL, openssl_pkey_get_private

388 views
Skip to first unread message

jwcarlton

unread,
Aug 30, 2011, 4:26:04 AM8/30/11
to
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

jwcarlton

unread,
Aug 30, 2011, 4:49:52 AM8/30/11
to

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.

ezequi...@gmail.com

unread,
Mar 17, 2018, 5:43:50 AM3/17/18
to
Thanks, That work perfect after 6 hours looking for a solution!
0 new messages