VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • 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;
}

相关教程