php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79677 sm2 curve public key encrypt->key type not supported in this PHP build
Submitted: 2020-06-05 08:09 UTC Modified: -
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: 1055358033 at qq dot com Assigned:
Status: Open Package: OpenSSL related
PHP Version: Irrelevant OS: ubuntu 16.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-06-05 08:09 UTC] 1055358033 at qq dot com
Description:
------------
---
From manual page: https://php.net/book.openssl
---

-----to begin with: sorry to bother, Im not sure this is a bug or i just get it wrong, i notice that there is two bug report look like mine, but why answer is between this problem will fixed in 5.6+ and openssl not support ec key...? and i really dont know who to turn to for this, appreciate it if you can answer me.

env: PHP Version 7.1.33-15+ubuntu16.04.1+deb.sury.org+1 openssl-1.1.1g

public/private Key generate by those commands:
./openssl ecparam -genkey -name SM2 -out priv.key
./openssl ec -in priv.key -pubout -out pub.key

then:
$pubKey = openssl_pkey_get_public('file://path/pub.key');
openssl_public_encrypt($data, $encrypted_data, $pubKey);

I tried to print $pubKey, nothing wrong here,
and this come out:
openssl_public_encrypt(): key type not supported in this PHP build!

openssl_get_curve_names() to make sure sm2 curve is supported, and it is.

in the end: really thanks if you can answer me this, plz let me know if I do
it the wrong way, thanks. below are my public/private Key

my publicKey=========->:

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE/J1aKDMqqIpVaudSK0XA/TfC4IFv
MYl2C5VQzCDpvSu6TPW4j8JzrvZg1fsuYhqbvdfFcNGHWLJ1jMNALGFtSg==
-----END PUBLIC KEY-----
my privateKey========->:

-----BEGIN EC PARAMETERS-----
BggqgRzPVQGCLQ==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIG8ejJ9q4va/aFwihqPNC6AooKwcV85/DlcCQpGiXCLyoAoGCCqBHM9V
AYItoUQDQgAE/J1aKDMqqIpVaudSK0XA/TfC4IFvMYl2C5VQzCDpvSu6TPW4j8Jz
rvZg1fsuYhqbvdfFcNGHWLJ1jMNALGFtSg==
-----END EC PRIVATE KEY-----






Test script:
---------------
public/private Key generate by those commands:
./openssl ecparam -genkey -name SM2 -out priv.key
./openssl ec -in priv.key -pubout -out pub.key

$pubKey = openssl_pkey_get_public('file://path/pub.key');
openssl_public_encrypt($data, $encrypted_data, $pubKey);

Expected result:
----------------
publicKey encrypted data

Actual result:
--------------
openssl_public_encrypt(): key type not supported in this PHP build!

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 04:01:23 2020 UTC