php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76016 EC keys not supported
Submitted: 2018-02-27 10:06 UTC Modified: 2018-03-02 13:52 UTC
From: nexwo at outlook dot com Assigned:
Status: Closed Package: OpenSSL related
PHP Version: 7.2.2 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nexwo at outlook dot com
New email:
PHP Version: OS:

 

 [2018-02-27 10:06 UTC] nexwo at outlook dot com
Description:
------------
---
From manual page: http://www.php.net/function.openssl-public-encrypt
---
Encrypt and decrypt don't work with EC keys.

Test script:
---------------
<?php
//openssl ecparam -name brainpoolP256r1 -genkey -noout -out ecprivkey.pem -param_enc explicit
//openssl ec -in ecprivkey.pem -pubout -out ecpubkey.pem
$privKeyString = "-----BEGIN EC PRIVATE KEY-----
MIIBUQIBAQQgN/imi4nGz/SJU7eB+XnFqja0Kns77jnvs9aZOT9cVHmggeMwgeAC
AQEwLAYHKoZIzj0BAQIhAKn7V9uh7qm8PmYKkJ2DjXJuO/Yj1SYgKCATSB0fblN3
MEQEIH1aCXX8LDBX7vZ1MEF6/+f7gFXBJtxcbOlKS0TzMLXZBCAm3Fxs6UpLRPMw
tdm713y/lYQWKVz34c5rzNwY/4wHtgRBBIvSrrnLflfLLEtIL/yBt6+53ifh470j
wjpEU72azjJiVH74NcPaxP2X+EYaFGEdycJ3RRMt7Y5UXB1Uxy8EaZcCIQCp+1fb
oe6pvD5mCpCdg41xjDl6o7VhpveQHg6Cl0hWpwIBAaFEA0IABJVkuTOWfb0IwE81
QepvTisqiCEdT6YnGsX7NbS4bwNEOrRJ/qdMxX3uwxATvg4ZtltbUENsEbzOVY5W
npwGRzw=
-----END EC PRIVATE KEY-----";
$pubKeyString = "-----BEGIN PUBLIC KEY-----
MIIBMzCB7AYHKoZIzj0CATCB4AIBATAsBgcqhkjOPQEBAiEAqftX26Huqbw+ZgqQ
nYONcm479iPVJiAoIBNIHR9uU3cwRAQgfVoJdfwsMFfu9nUwQXr/5/uAVcEm3Fxs
6UpLRPMwtdkEICbcXGzpSktE8zC12bvXfL+VhBYpXPfhzmvM3Bj/jAe2BEEEi9Ku
uct+V8ssS0gv/IG3r7neJ+HjvSPCOkRTvZrOMmJUfvg1w9rE/Zf4RhoUYR3JwndF
Ey3tjlRcHVTHLwRplwIhAKn7V9uh7qm8PmYKkJ2DjXGMOXqjtWGm95AeDoKXSFan
AgEBA0IABKDy7MQoapZryIVWzzv/ctOoAOabi+rcgpdML3q6Jw3zjHpp5/E7tfBa
4LmXZn3ioAXYBvlGnvneltTu1/muIrg=
-----END PUBLIC KEY-----";

$privKey = openssl_pkey_get_private($privKeyString);

// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_public($pubKeyString);

$data = 'plaintext data goes here';

// Encrypt the data to $encrypted using the public key
openssl_public_decrypt($data, $encrypted, $pubKey);

// Decrypt the data using the private key and store the results in $decrypted
openssl_private_decrypt($encrypted, $decrypted, $privKey);

echo $decrypted;
?>

Expected result:
----------------
plaintext data goes here

Actual result:
--------------
PHP Warning:  openssl_public_decrypt(): key type not supported in this PHP build! in C:\test.php on line 32
PHP Warning:  openssl_private_decrypt(): key type not supported in this PHP build! in C:\test.php on line 35

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-02 13:52 UTC] nexwo at outlook dot com
-Status: Open +Status: Closed
 [2018-03-02 13:52 UTC] nexwo at outlook dot com
OpenSSL not support ECIES!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jan 25 11:01:23 2021 UTC