Is there a possibility in PHP's OpenSSL implementation to encrypt via public key/decrypt via private key using PHP OpenSSL?
As per the OpenSSL documentation, openssl_seal() does not support an EC public key.
The public key must be RSA because it is the only OpenSSL public key algorithm that supports key transport.
openssl_public_encrypt() also throws an error when using it with an EC key.
My key creation works as follows:
// Configuration settings for the key
$config = array(
"private_key_type" => OPENSSL_KEYTYPE_EC,
"curve_name" => "secp521r1"
);
// Create the private and public key
$res = openssl_pkey_new($config);
// Extract the private key into $private_key
openssl_pkey_export($res, $private_key);
// Extract the public key into $public_key
$public_key = openssl_pkey_get_details($res);
$public_key = $public_key["key"];
Is there any way to do ec public key encryption with OpenSSL?
Why is the failure of openssl() and openssl_public_encrypt() for EC not documented at php.net?