I have to encrypt the generated symmetric key (AES-256-CBC) with asymmetric encryption in PHP. I got a public certificate (CER file) I should use. I try to do it like this:
$fp = fopen('publickey.cer', 'r');
$pub_key = fread($fp, filesize('publickey.cer'));
fclose($fp);
openssl_public_encrypt($enc, $final, $pub_key, OPENSSL_PKCS1_PADDING);
where $enc is my symmetric key
I'm receiving output ($final) which is incorrect.
The working code in Java that works fine looks like this:
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding") ;
cipher.init(Cipher.ENCRYPT_MODE, x509Certificate.getPublicKey());
return cipher.doFinal(bytes) ;
How to transform it into PHP?