public static bool ValidateBySecureKey(Dictionary <string, string> dictionary, string secureKey) { if (!dictionary.ContainsKey("signMethod") || !dictionary.ContainsKey("signature")) { return(false); } var result = false; var signMethod = dictionary["signMethod"]; if ("11" == signMethod) { var stringSign = dictionary["signature"]; dictionary.Remove("signature"); var stringData = GetSignContent(dictionary, true, false); var strBeforeSha256 = stringData + "&" + SHA256.Compute(secureKey); var strAfterSha256 = SHA256.Compute(strBeforeSha256); result = stringSign == strAfterSha256; } else if ("12" == signMethod) { var stringSign = dictionary["signature"]; dictionary.Remove("signature"); var stringData = GetSignContent(dictionary, true, false); var strBeforeSm3 = stringData + "&" + SM3.Compute(secureKey); var strAfterSm3 = SM3.Compute(strBeforeSm3); result = stringSign == strAfterSm3; } return(result); }
public static bool ValidateBySecureKey(Dictionary <string, string> rspData, string secureKey) { if (!rspData.ContainsKey("signMethod") || !rspData.ContainsKey("signature")) { return(false); } var signMethod = rspData["signMethod"]; var result = false; if ("11".Equals(signMethod)) { var stringSign = rspData["signature"]; rspData.Remove("signature"); var stringData = GetSignContent(rspData, true, false); var strBeforeSha256 = stringData + "&" + SHA256.Compute(secureKey); var strAfterSha256 = SHA256.Compute(strBeforeSha256); result = stringSign.Equals(strAfterSha256); } else if ("12".Equals(signMethod)) { var stringSign = rspData["signature"]; rspData.Remove("signature"); var stringData = GetSignContent(rspData, true, false); var strBeforeSm3 = stringData + "&" + SM3.Compute(secureKey); var strAfterSm3 = SM3.Compute(strBeforeSm3); result = stringSign.Equals(strAfterSm3); } else { return(false); } return(result); }
public static void SignBySecureKey(Dictionary <string, string> dictionary, string secureKey) { if (!dictionary.ContainsKey("signMethod")) { throw new UnionPayException("signMethod must Not null"); } var stringData = GetSignContent(dictionary, true, false); var signMethod = dictionary["signMethod"]; if ("11" == signMethod) { var strBeforeSha256 = stringData + "&" + SHA256.Compute(secureKey); var strAfterSha256 = SHA256.Compute(strBeforeSha256); //设置签名域值 dictionary["signature"] = strAfterSha256; } else if ("12" == signMethod) { var strBeforeSm3 = stringData + "&" + SM3.Compute(secureKey); var strAfterSm3 = SM3.Compute(strBeforeSm3); //设置签名域值 dictionary["signature"] = strAfterSm3; } else { throw new UnionPayException("Error signMethod [" + signMethod + "] in SignBySecureKey. "); } }
public static void SignBySecureKey(Dictionary <string, string> reqData, string secureKey) { if (!reqData.ContainsKey("signMethod")) { throw new Exception("signMethod must Not null"); } var signMethod = reqData["signMethod"]; var stringData = GetSignContent(reqData, true, false); if ("11".Equals(signMethod)) { var strBeforeSha256 = stringData + "&" + SHA256.Compute(secureKey); var strAfterSha256 = SHA256.Compute(strBeforeSha256); //设置签名域值 reqData["signature"] = strAfterSha256; } else if ("12".Equals(signMethod)) { var strBeforeSm3 = stringData + "&" + SM3.Compute(secureKey); var strAfterSm3 = SM3.Compute(strBeforeSm3); //设置签名域值 reqData["signature"] = strAfterSm3; } else { throw new Exception("Error signMethod [" + signMethod + "] in SignBySecureKey. "); } }