0

I want to learn OpenSSL but I'm just getting boolean false when I am trying to use this code:

$config = array('private_key_bits' => 512);
$privKey = openssl_pkey_new($config);

var_dump($privKey);

The OpenSSL extension is activated on my server. Have I missed something?

jww
  • 97,681
  • 90
  • 411
  • 885
Airikr
  • 6,258
  • 15
  • 59
  • 110

1 Answers1

0

Use openssl_error_string() after your openssl_* function is called:

while($e = openssl_error_string() ) {
    print_r($e."\n");
}

On my Windows it outputs:

error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib
error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib

See the first note at this function openssl_pkey_new():

Note: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.

Glavić
  • 42,781
  • 13
  • 77
  • 107