/**
* 验证签名
* TobeVerified 待验证签名的密文
* PlainText 待验证签名的明文
* CertFile 签名者公钥证书
* return 验证成功返回true,失败返回false(从LastErrMsg属性获取失败原因)
*/
function VerifyMsg($TobeVerified, $PlainText, $CertFile,$signature_alg=OPENSSL_ALGO_SHA1)
{
//用公钥验签
$fp=fopen($CertFile,"r");
if(!$fp)
{
//echo "Error Number:-10005, Error Description: ER_FIND_CERT_FAILED(找不到证书)";
return false;
}
$pub_key=fread($fp,8192);
fclose($fp);
$res = openssl_get_publickey($pub_key);
if (1==openssl_verify($PlainText,pack("H" . strlen($TobeVerified), $TobeVerified) , $res,$signature_alg))
{
//print("www.bKjia.c0m提示您:验证成功"." ");
return true;
}
else
{
//echo "Error Number:-10021, Error Description: ER_VERIFY_ERROR(验签失败)|".openssl_error_string();
return false;
}
}
?>
|