public static void CheckResponseSign <T>(IAopRequest <T> request, string responseBody, bool isError, IAopParser <T> parser, string alipayPublicKey, string charset, string signType, bool keyFromFile) where T : AopResponse { if (string.IsNullOrEmpty(alipayPublicKey) || string.IsNullOrEmpty(charset)) { return; } SignItem signItem = parser.GetSignItem(request, responseBody); if (signItem == null) { throw new AopException("sign check fail: Body is Empty!"); } if ((!isError || (isError && !string.IsNullOrEmpty(signItem.Sign))) && !AlipaySignature.RSACheckContent(signItem.SignSourceDate, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile)) { if (string.IsNullOrEmpty(signItem.SignSourceDate) || !signItem.SignSourceDate.Contains("\\/")) { throw new AopException("sign check fail: check Sign and Data Fail!"); } string signContent = signItem.SignSourceDate.Replace("\\/", "/"); if (!AlipaySignature.RSACheckContent(signContent, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile)) { throw new AopException("sign check fail: check Sign and Data Fail JSON also"); } } }
private void CheckResponseSign <T>(IAopRequest <T> request, string responseBody, bool isError, IAopParser <T> parser) where T : AopResponse { if (string.IsNullOrEmpty(alipayPublicKey) || string.IsNullOrEmpty(charset)) { return; } SignItem signItem = parser.GetSignItem(request, responseBody); if (signItem == null) { throw new AopException("sign check fail: Body is Empty!"); } if (!isError || (isError && !string.IsNullOrEmpty(signItem.Sign))) { bool rsaCheckContent = AlipaySignature.RSACheckContent(signItem.SignSourceDate, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile); if (!rsaCheckContent) { if (!string.IsNullOrEmpty(signItem.SignSourceDate) && signItem.SignSourceDate.Contains("\\/")) { string srouceData = signItem.SignSourceDate.Replace("\\/", "/"); bool jsonCheck = AlipaySignature.RSACheckContent(srouceData, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile); if (!jsonCheck) { throw new AopException( "sign check fail: check Sign and Data Fail JSON also"); } } else { throw new AopException( "sign check fail: check Sign and Data Fail!"); } } } }