PHP RSA签名
/**
* rsa签名
* @param $data 待签名数据
* @param $private_key 私钥字符串
* return 签名结果
*/
function rsasign($data, $private_key,$sign_type='sha256') {
$search = [
"-----begin rsa private key-----",
"-----end rsa private key-----",
"\n",
"\r",
"\r\n"
];
$private_key=str_replace($search,"",$private_key);
$private_key=$search[0] . php_eol . wordwrap($private_key, 64, "\n", true) . php_eol . $search[1];
$res=openssl_get_privatekey($private_key);
if($res)
{
openssl_sign($data, $sign,$res,$sign_type);
openssl_free_key($res);
}else {
exit("私钥格式有误");
}
$sign = base64_encode($sign);
return $sign;
}