Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        public async void UserRegister(string userName, string userPassword, string userDeviceCode)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("action", "registerUser");
            dic.Add("user_name", RSAEncryptHelper.PublicEncrypt(userName));
            dic.Add("user_password", RSAEncryptHelper.PublicEncrypt(userPassword));
            User response = await PostDictionary <User>(dic);
        }
Exemplo n.º 3
0
        public async Task <bool> SignInAsync(SignInInput accountPassword)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("action", "userLogin");
            dic.Add("user_name", RSAEncryptHelper.PublicEncrypt(accountPassword.Account));
            dic.Add("user_password", RSAEncryptHelper.PublicEncrypt(accountPassword.Password));
            User user = await PostDictionary <User>(dic);

            if (user != null)
            {
                AppEnvironment.Instance.CurrentUser = user;
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 计算指纹
        /// </summary>
        /// <param name="signature">客户端传回的指纹</param>
        /// <returns></returns>
        private string GetSignature(string signature)
        {
#if DEBUG
            var    keys       = RSAEncryptHelper.GetRSAKey();
            string publicKey  = keys.PublicKey;
            string privateKey = keys.PrivateKey;
            Trace.WriteLine("publicKey:" + publicKey);
            Trace.WriteLine("privateKey:" + privateKey);
#endif

            //解密私钥客户端传回的指纹
            string argSignString = RSAEncryptHelper.DecryptString(signature, PrivateKey);
            _logHelper.Debug("*使用私钥解密客户端传回的指纹*:" + argSignString + "\r\n");

            //取解密后字符串的md5
            //string md5 = Md5Helper.Md5(argSignString);

            return(argSignString);
        }