public VerifyData ( |
||
data | ||
signature | byte | |
hashAlgorithm | Internal.Cryptography.HashAlgorithmName | |
padding | RSASignaturePadding | |
리턴 | bool |
public override bool Verify(byte[] signature) { HashAlgorithm hash = HashAlgorithm.Create("SHA1"); byte[] toBeVerified = hash.ComputeHash(ms.ToArray()); //return PKCS1.Verify_v15 (rsa, hash, toBeVerified, signature); return(rsa.VerifyData(ms.ToArray(), signature, new HashAlgorithmName("SHA1"), RSASignaturePadding.Pkcs1)); }
public bool Verify(string data, string sign) { byte[] dataBytes = _encoding.GetBytes(data); byte[] signBytes = Convert.FromBase64String(sign); var verify = _publicKeyRsaProvider.VerifyData(dataBytes, signBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1); return(verify); }
/// <summary> /// RSA Verify /// </summary> /// <param name="content">raw content</param> /// <param name="signStr">sign str</param> /// <param name="publickKey">public key</param> /// <param name="hashAlgorithmName">hashAlgorithm name</param> /// <param name="rSASignaturePadding">ras siginature padding</param> /// <param name="encoding">text encoding</param> /// <returns></returns> public static bool RSAVerify(string content, string signStr, string publickKey, HashAlgorithmName hashAlgorithmName, RSASignaturePadding rSASignaturePadding, Encoding encoding) { Check.Argument.IsNotEmpty(content, nameof(content)); Check.Argument.IsNotEmpty(signStr, nameof(signStr)); byte[] dataBytes = encoding.GetBytes(content); byte[] signBytes = Convert.FromBase64String(signStr); using (System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create()) { rsa.FromJsonString(publickKey); return(rsa.VerifyData(dataBytes, signBytes, hashAlgorithmName, rSASignaturePadding)); } }
public TaskStatus Handle(IHttpProxy httpProxy) { using (CLog log = new CLog("Alipay Notify", false)) { var data = GetRequestData(httpProxy.Form); var dataJson = Newtonsoft.Json.JsonConvert.SerializeObject(data); log.Log(dataJson); if (data.Count > 0) { string out_trade_no = data["out_trade_no"]; string sign = httpProxy.Form["sign"]; //string sign_type = form["sign_type"]; PayFactory.OnLog(out_trade_no, LogEventType.ReceiveNotify, dataJson); var config = new Config(PayFactory.GetInterfaceXmlConfig(PayInterfaceType.AlipayScanQRCode, out_trade_no)); var signStr = Helper.GetUrlString(data, false); System.Security.Cryptography.RSA rsacore = Way.Lib.RSA.CreateRsaFromPublicKey(config.alipayPublicKey); var isPass = rsacore.VerifyData(Encoding.GetEncoding("utf-8").GetBytes(signStr), Convert.FromBase64String(sign), HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1); if (isPass == false) { log.Log("sign:{0}", sign); log.Log("签名不一致"); httpProxy.ResponseWrite("fail"); return(TaskStatus.Completed); } //支付宝交易号 string trade_no = data["trade_no"]; //交易状态 //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。 string trade_status = data["trade_status"]; double?receipt_amount = null; try { receipt_amount = Convert.ToDouble(data["receipt_amount"]); } catch { } log.Log(trade_status); if (trade_status == "TRADE_SUCCESS") { log.Log("excute OnPaySuccessed"); PayFactory.OnPaySuccessed(out_trade_no, receipt_amount, null, dataJson); } httpProxy.ResponseWrite("success"); } else { httpProxy.ResponseWrite("无通知参数"); } } return(TaskStatus.Completed); }
public bool VerifyData(byte[] buffer, object halg, byte[] signature) => _impl.VerifyData(buffer, signature, HashAlgorithmNames.ObjToHashAlgorithmName(halg), RSASignaturePadding.Pkcs1);