Receiver has given me a public key and I need to use it to encrypt username and password. I have done various r&d but nothing works. I have used
function public_encrypt($plaintext)
{
$fp=fopen("private.key","r");
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
openssl_public_encrypt($plaintext,$crypttext, $pub_key);
return(base64_encode($crypttext));
}
But it gives me openssl_public_encrypt(): key parameter is not a valid public key error.
I have also added begin and end line to key, but still no success Kindly guide me with steps to follow as I am new in it.
----PUBLIC KEY START----? That's not the correct delimiter in any of the encoding formats.