I am trying to use the following PHP code in a project that I am working on.
https://www.virendrachandak.com/techtalk/encryption-using-php-openssl/
When I try to use the openssl_pkey_new method, I get the following error message, which, it seems to me, is due to the incorrect openssl.cnf configuration.
Error messages
error: 09072007: PEM routines: PEM_write_bio: BUF error lib: 0906D06C: PEM
routines: PEM_read_bio: no initial line error: 0906D06C: PEM
routines: PEM_read_bio: no initial line error: 0E06D06C: configuration file
routines: NCONF_get_string: no value error: 0E06D06C: configuration file
routines: NCONF_get_string: no value error: 0E06D06C: configuration file
routines: NCONF_get_string: no value error: 0E06D06C: configuration file
routines: NCONF_get_string: no value error: 0E06D06C: configuration file
routines: NCONF_get_string: no value error: 0E06D06C: configuration file
The public key is generated, but there is no private key. I am using xampp 5.6.3-0 on mac osx 10.10.1 (14B25)
Here is the contents of opensl.cnf.
#
Does anyone know what I'm doing wrong and can help me fix this problem? thanks
UPDATE I upgraded openssl to the latest version 1.0.1j using homebrew and I changed the location of openssl.cnf from / Applications / XAMPP / xamppfiles / share / openssl / to / usr / local / etc / openssl
and then, using the following tutorial, I created SSL certificates
Create and use SSL certificates
Using this, I managed to create public and private keys that can encrypt and decrypt, but still I have the following errors.
error:0906D06C:PEM routines:PEM_read_bio:no start line error:0906D06C:PEM routines:PEM_read_bio:no start line error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value error:0E06D06C:configuration file routines:NCONF_get_string:no value
Here is my php code
$config = array( 'private_key_bits' => 2048, // Size of Key. 'private_key_type' => OPENSSL_KEYTYPE_RSA, ); $res = openssl_pkey_new($config); while ($msg = openssl_error_string()) echo $msg . "<br />\n";