[Q] openssl_pkey_new() returns NULL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm trying encrypt/decrypt in PHP, but I can't.
openssl_pkey_new() should return resource ID or FALSE,
but it always returns NULL in actual.

The following is the code I tried:


  $crf_path = '/etc/pki/tls/openssl.cnf';    # for CentOS
  #$crf_path = '/opt/local/etc/openssl/openssl.cnf';   # for MacPorts
  is_file($crf_path)  or die("$crf_path: not found.");

  $config = array("config"=>$crf_path);
  $resource = openssl_pkey_new($config);
  var_export($resource);   #=> NULL


I runned above code in both CentOS and Mac OS X, and found
that openssl_pkey_new() always returns NULL in both case.

Is there any mistake in the above code?
Why does openssl_pkey_new() return NULL instead of resource ID?

I need your help.

makoto kuwata

Re: [Q] openssl_pkey_new() returns NULL

On Wed, 12 Aug 2009 22:25:35 -0700 (PDT), makoto kuwata

Quoted text here. Click to load it

[ snip code ]

Quoted text here. Click to load it

Is your version of PHP compiled with OpenSSL enabled? Seems to work ok

tk@brain:~ $ php -r '$res = openssl_pkey_new(array("config" =>
"/etc/ssl/openssl.cnf")); var_dump($res);'
resource(4) of type (OpenSSL key)

tk@brain:~ $ php -i | grep OpenSSL
cURL Information => libcurl/7.18.0 OpenSSL/0.9.8e zlib/1.2.3
OpenSSL support => enabled
OpenSSL Version => OpenSSL 0.9.8e 23 Feb 2007



Re: [Q] openssl_pkey_new() returns NULL

makoto kuwata wrote:
Quoted text here. Click to load it

Is your openssl configured properly?  Does your user (i.e. the web
server user, if you're running this from a web page) have read access to
the files?

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline