I need to send a password that's RSA encrypted with a public key (along with some other data). Here are the exact instructions from the documentation for the password:
Encode password in Base64 and ensure UTF-8 encoding
Encrypt password with RSA with provided public key, no block mode, and PKCS1Padding
Encode resulting encryption in Base64 with ensured UTF-8 encoding
Here's the code I'm using that to me seems correct:
function encryptPassword($pass) {
$pass = base64_encode($pass);
$fp = fopen("./cert.crt", "r");
$publicKey = fread($fp, 8192);
fclose($fp);
openssl_get_publickey($publicKey);
openssl_public_encrypt($pass, $cryptedText, $publicKey, OPENSSL_PKCS1_PADDING);
return base64_encode(utf8_encode($cryptedText));
}
I'm getting an error on the other side saying the password can't be decoded. Support from them is basically non-existent other than the error message, and them saying everything is correct on their side. My question is, am I sending what they're asking for according to the documentation?
Thanks in advance!