PHP with openSSL public parameter cannot be forced into private key

I am trying to sign a file using a function openssl_sign(). I have the following secret key: -----BEGIN EC PRIVATE KEY----- MHQCAQEEIDzQVg9bJ1kZFsZDoLeqadA4OTgKc40ukSmQ3MVzcV0soAcGBSuBBAAK oUQDQgAEvzUNKCE3UVimCLUePomOUH/kfy0ujHdN5Kmn7ez3TtokJDy5ksVnOgf6 WzpmzY46zvKAnQ44Cgx5Kdqx5dVDiw== -----END EC PRIVATE KEY-----

I use the following function: openssl_sign("test", $signature, $private_key, OPENSSL_ALGO_SHA256);.

I have one server that can sign using this key, and the other does not. One that has PHP 5.6, and one that does not have PHP 7.1. Why can one server use a key and another not?

+4
source share
2 answers

Perhaps you need to use the openssl_get_privatekeyprivate key to create the resource, and not just use the string

$str_priv_key='-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIDzQVg9bJ1kZFsZDoLeqadA4OTgKc40ukSmQ3MVzcV0soAcGBSuBBAAK
oUQDQgAEvzUNKCE3UVimCLUePomOUH/kfy0ujHdN5Kmn7ez3TtokJDy5ksVnOgf6
WzpmzY46zvKAnQ44Cgx5Kdqx5dVDiw==
-----END EC PRIVATE KEY-----';

$pkey=openssl_get_privatekey( $str_priv_key );
openssl_sign( "test", $signature, $pkey );
openssl_free_key( $pkey );

According to the PHP manual, the private key parameter must be a resource

> priv_key_id
> resource - a key, returned by openssl_get_privatekey()
0

, , OpenSSL. ,

phpinfo();

: " OpenSSL ". .

, :

error_get_last()
Usage: print_r(error_get_last());

openssl_error_string()
Usage: echo openssl_error_string();

"error_get_last()":

openssl_sign():

"openssl_error_string()":

: 100AE081: : EC_GROUP_new_by_curve_name:

, OpenSSL EC. "EC_GROUP_new_by_curve_name" "static const ec_list_element curve_list []" . "".

3 :

  • OpenSSL, .
  • , .
  • EC.

PHP 7.1.0 :

openssl_get_curve_names()

. PHP 5.6, , , , , .

: Linux, RedHat CentOS, OpenSSL, . , OpenSSL (5.8) CentOS. (, https://syslint.com/blog/tutorial/how-to-upgrade-openssl-on-centos-7-or-rhel-7/), OpenSSL. , PHP "" OpenSSL, OpenSSL , PHP.

0

Source: https://habr.com/ru/post/1691407/


All Articles