公钥加密 openssl_public_encrypt(): key parameter is not a valid public key
公钥加密处理报错, openssl_public_encrypt(): key parameter is not a valid public key
1.开启open_ssl扩展
2.转化再加密
下载的公钥形式类似 '-----BEGIN PUBLIC KEY-----\nMIGTDVGHWDFNADCBiQKBgQ99XZ6WiHxh94IAKTgSOEev\n6tASj3XKVnssChGIZaSvdRXiJshGaR1LNeDbWSDFWE8OjA9sPlwgLJabnP\nWR283fGu7nRm9\/sc4HKRETEF2bj7rcMeEAQAB\n-----END PUBLIC KEY-----'
去掉 \n、\/,
$str = str_replace(array("\r\n", "\r", "\n"), "", $str);
$this->public_key = 'MIGTDVGHWDFNADCBiQKBgQ99XZ6WiHxh94IAKTgSOEev6tASj3XKVnssChGIZaSvdRXiJshGaR1LNeDbWSDFWE8OjA9sPlwgLJabnPWR283fGu7nRm9sc4HKRETEF2bj7rcMeEAQAB';
再重新拼接 "-----BEGIN PUBLIC KEY-----\n" . wordwrap($this->public_key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"用来加密
copy from: https://www.cnblogs.com/qiuphp/p/13603337.html