/// <summary> /// 指纹校验 /// </summary> /// <param name="signature">客户端传回的指纹</param> /// <param name="actionArguments">请求参数</param> /// <returns></returns> private bool CheckSignature(string signature, Dictionary <string, object> actionArguments) { //if (string.IsNullOrEmpty(signature)) return false; if (actionArguments != null) { _logHelper.Debug("开始Signature校验,参数个数:" + actionArguments.Count + "。\r\n"); //1-获取参数字符串,并按参数名升序排序,最后统一转成小写,形如:a1b2c3 string argString = this.GetArgumentString(actionArguments); _logHelper.Debug("1-获取参数字符串,并按参数名升序排序,最后统一转成小写:" + argString + "\r\n"); //2-取参数字符串的md5 string sign = Md5Helper.Md5(argString); _logHelper.Debug("2-取参数字符串的md5:" + sign + "\r\n"); //3-【客户端】使用公钥加密参数字符串的md5后传回服务器 string signEncrypt = RSAEncryptHelper.EncryptString(sign, PublicKey); _logHelper.Debug("3-使用公钥加密参数字符串的md5(服务器计算的值):" + signEncrypt + "\r\n"); //4-使用私钥解密客户端传回的指纹 signature = this.GetSignature(signature); _logHelper.Debug("4-使用私钥解密客户端传回的指纹:" + signature + "\r\n"); _logHelper.Debug("5-校验指纹信息:" + (sign == signature).ToString() + "\r\n"); return(sign == signature); } return(false); }
private void RsaTest() { var key = RSAEncryptHelper.GetRSAKey(); Console.WriteLine("PublicKey:" + key.PublicKey + "\r\n"); Console.WriteLine("PrivateKey:" + key.PrivateKey + "\r\n"); string source = @"RSAEncryptHelper"; if (RSAEncryptHelper.CheckSourceValidate(source)) { string e = RSAEncryptHelper.EncryptString(source, key.PublicKey); Console.WriteLine("加密后:" + e + "\r\n"); string d = RSAEncryptHelper.DecryptString(e, key.PrivateKey); Console.WriteLine("解密后:" + d); } }