openssl_pkey_export_to_file bug?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
karstensrage
Forum Newbie
Posts: 2
Joined: Thu Mar 08, 2012 11:20 pm

openssl_pkey_export_to_file bug?

Post by karstensrage »

Im running into an issue that seems non-obvious to me how to address. Basically this works:

openssl_pkey_export_to_file($privkey, './test.key.pem', 'test');
$return = openssl_pkey_get_private('file://./test.key.pem', 'test');

But this, does not:

openssl_pkey_export_to_file($privkey, './test.key.pem', '');
$return = openssl_pkey_get_private('file://./test.key.pem', '');

The call to openssl_pkey_export_to_file in both cases works and creates an encrypted PEM file. Unfortunately you cant decrypt the PEM file in the second case. Is there a way to specify a password of the empty string for decryption since it will take the empty string for encryption?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: openssl_pkey_export_to_file bug?

Post by requinix »

You could just... not use the parameter. Since it's optional and all.

Code: Select all

openssl_pkey_export_to_file($privkey, './test.key.pem');
$return = openssl_pkey_get_private('file://./test.key.pem');
karstensrage
Forum Newbie
Posts: 2
Joined: Thu Mar 08, 2012 11:20 pm

Re: openssl_pkey_export_to_file bug?

Post by karstensrage »

Sure, but that creates an un-encrypted key. I'm in a situation where a key was already exported with the empty string password and I'm trying to figure out how to use it.
Post Reply