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: 2021-11-21 04:22 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: 1055358033 at qq dot com Assigned: cmb (profile)
Status: No Feedback 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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-09 09:24 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-11-09 09:24 UTC] cmb@php.net
> PHP Version 7.1.33-15+ubuntu16.04.1+deb.sury.org+1

PHP 7.1 is no longer actively supported for roughly three years.
Do you still experience this issue with any of the actively
supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-11-21 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 19:01:28 2024 UTC