Page 1 of 1

openssl_pkey_export_to_file bug?

Posted: Thu Mar 08, 2012 11:26 pm
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?

Re: openssl_pkey_export_to_file bug?

Posted: Thu Mar 08, 2012 11:51 pm
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');

Re: openssl_pkey_export_to_file bug?

Posted: Fri Mar 09, 2012 7:05 am
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.