/// <summary> /// 获取返回时的签名验证结果 /// </summary> /// <param name="inputPara">通知返回参数数组</param> /// <param name="sign">对比的签名结果</param> /// <returns>签名验证结果</returns> private static bool GetSignVeryfy(SortedDictionary <string, string> inputPara, string sign, SignType signType) { Dictionary <string, string> sPara = new Dictionary <string, string>(); //过滤空值、sign与sign_type参数 sPara = PayUtil.FilterPara(inputPara); //获取待签名字符串 string preSignStr = PayUtil.CreateLinkString(sPara); //获得签名验证结果 bool isSgin = false; if (sign != null && sign != "") { switch (signType) { case SignType.RSA: isSgin = RSAUtil.RASVerify(preSignStr, sign, _public_key, _input_charset); break; case SignType.MD5: isSgin = MD5Util.Verify(preSignStr, sign, _key, _input_charset); break; default: break; } } return(isSgin); }
/// <summary> /// 生成请求时的签名 /// </summary> /// <param name="sPara">请求给支付宝的参数数组</param> /// <returns>签名结果</returns> public static string BuildRequestMysign(Dictionary <string, string> sPara, SignType signType, string inputCharset) { //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 string prestr = CreateLinkString(sPara); //把最终的字符串签名,获得签名结果 //目前用MD5签名 string mysign = ""; switch (signType) { case SignType.MD5: mysign = MD5Util.Sign(prestr, PayConfigUtil.KEY, inputCharset); break; case SignType.RSA: mysign = RSAUtil.RSASign(prestr, PayConfigUtil.RSA_PRIVATEKEY, inputCharset); break; case SignType.MD5Innner: mysign = MD5Util.Sign(prestr, PayConfigUtil.ENCRYPT_SALT, inputCharset); break; default: mysign = ""; break; } return(mysign); }