public override void OnAuthorization(AuthorizationContext filterContext)
        {
            HttpRequestBase     Request    = filterContext.RequestContext.HttpContext.Request;
            NameValueCollection parameters = new NameValueCollection()
            {
                Request.Form,
                Request.QueryString
            };

            string sign = parameters["sign"];

            parameters.Remove("sign");
            List <string> paramlist = new List <string>();

            foreach (var item in parameters.AllKeys.OrderBy(k => k))
            {
                paramlist.Add(item + "=" + HttpUtility.UrlDecode(parameters[item]));
            }
            string presignstr = string.Join("&", paramlist);
            string digest     = RSAHelper.DecryptString(sign, ConfigurationManager.AppSettings[PrivateKey]);

            if (Sha1.Compute(presignstr) != digest)
            {
                ContentResult result = new ContentResult();
                result.Content       = "Sign Error.";
                filterContext.Result = result;
            }
        }
Ejemplo n.º 2
0
        private const string EncryptValue = "5bvv"; // TODO 可配置 AxOne
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var headers = filterContext.Request.Headers;
            var data    = new ResponseExtensionData
            {
                CallResult          = CallResult.Unauthorized,
                RetMsg              = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckAppAttribute_OnActionExecuting_RetMsg"),
                ModelValidateErrors = new List <ModelValidateError>()
            };

            if (headers.Contains("appkey"))
            {
                var appKeyStr = headers.GetValues("appkey").First();
                var authKeys  = ((IContainer)HttpRuntime.Cache["containerKey"]).Resolve <IAuthKeysBusiness>().GetAuthKeys(0, AuthUserType.Application);
                if (string.IsNullOrEmpty(appKeyStr) || authKeys == null || string.IsNullOrWhiteSpace(authKeys.PrivateKey))
                {
                    filterContext.Response = filterContext.ControllerContext.Request.CreateErrorResponseByReturnType(filterContext, data);
                    return;
                }
                var encryptValue = RSAHelper.DecryptString(appKeyStr, authKeys.PrivateKey);
                if (string.IsNullOrWhiteSpace(encryptValue) || !string.Equals(encryptValue, EncryptValue))
                {
                    filterContext.Response = filterContext.ControllerContext.Request.CreateErrorResponseByReturnType(filterContext, data);
                    return;
                }
            }
            else
            {
                filterContext.Response = filterContext.ControllerContext.Request.CreateErrorResponseByReturnType(filterContext, data);
                return;
            }
            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 3
0
 //对注册密钥文件进行解密
 public static bool DecryptRegKey(string file)
 {
     try
     {
         string   regMsg  = EncryptHelper.FileDecrypt(file);
         string[] regList = regMsg.Split(new String[] { getCpu }, StringSplitOptions.RemoveEmptyEntries);
         string   mNum    = RSAHelper.DecryptString(regList[0]);
         if (mNum == getMNum())
         {
             Com = RSAHelper.DecryptString(regList[1]);
             Usr = RSAHelper.DecryptString(regList[2]);
             return(true);
         }
         else
         {
             MessageBox.Show("注册密钥机器码不正确!");
             return(false);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("解析注册密钥文件失败!\n" + ex.Message);
         return(false);
     }
 }
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            StartTimer(true);

            if (_rsa == null)
            {
                MessageBox.Show("Lütfen Anahtar boyunu geriniz.!");
                StopTimer(true);

                return;
            }
            if (string.IsNullOrEmpty(txtDecryptInputContent.Text))
            {
                MessageBox.Show("Lütfen şifrelenmiş metini giriniz.!");
                StopTimer(true);

                return;
            }
            try
            {
                txtDecryptOutContent.Text = _rsa.DecryptString(txtDecryptInputContent.Text, txtPrivateKey.Text);
            }
            catch (Exception ex)
            {
                txtDecryptOutContent.Text   = "";
                txtDecryptInputContent.Text = "";
                MessageBox.Show("Metin içeriğini şifrelemeye çalışırken bir hata oluştu.Anahtar boyutunun metin boyutuna uygun olup olmadığını kontrol edin!!");
                StopTimer(true);
            }
            StopTimer(true);
        }
        public void OnResponse_MSG_G2C_EncryptKey(MemoryStream stream, int uid = 0)
        {
            MSG_G2C_EncryptKey MSG_G2C_EncryptKey = ProtoBuf.Serializer.Deserialize <MSG_G2C_EncryptKey>(stream);

            Parser.Parse(MSG_G2C_EncryptKey);
            string encryptKey = RSAHelper.DecryptString(MSG_G2C_EncryptKey.EncryptKey, _publicKey);

            SetBlowFish(new BlowFish(encryptKey));
        }
Ejemplo n.º 6
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var headers    = filterContext.Request.Headers;
            var result     = new ResponsePackage <object>();
            var extionData = new ResponseExtensionData
            {
                ModelValidateErrors = new List <ModelValidateError>(),
                CallResult          = CallResult.Unauthorized,
                RetMsg = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckAppLoginAttribute_OnActionExecuting_RetMsg")
            };

            if (!headers.Contains("uid"))
            {
                result.Data            = null;
                result.ExtensionData   = extionData;
                filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, result);
                return;
            }
            var uid = Convert.ToInt32(headers.GetValues("uid").First());

            if (headers.Contains("token") && uid > 0)
            {
                const AuthUserType userType = (AuthUserType)2;
                var tokenEncryptStr         = headers.GetValues("token").First();
                var authKeys = ((IContainer)HttpRuntime.Cache["containerKey"]).Resolve <IAuthKeysBusiness>().GetAuthKeys(uid, userType);
                if (string.IsNullOrEmpty(tokenEncryptStr) || authKeys == null || authKeys.PrivateKey == null)
                {
                    result.Data            = null;
                    result.ExtensionData   = extionData;
                    filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, result);
                    return;
                }
                var tokenDecryptStr = RSAHelper.DecryptString(tokenEncryptStr, authKeys.PrivateKey);
                if (string.IsNullOrWhiteSpace(tokenDecryptStr) || !string.Equals(tokenDecryptStr, uid.ToString()))
                {
                    result.Data            = null;
                    result.ExtensionData   = extionData;
                    filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, result);
                    return;
                }
            }
            else
            {
                result.Data            = null;
                result.ExtensionData   = extionData;
                filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, result);
                return;
            }
            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 7
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            var _val = txtDecryptString.Text;
            var _key = txtDecryptSecret.Text;

            if (string.IsNullOrEmpty(_val) || string.IsNullOrEmpty(_key))
            {
                MessageBox.Show("需要解密的密文和解密密钥均不能为空,请重试。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                txtDecryptResult.Text = RSAHelper.DecryptString(_val, _key);
            }
        }
Ejemplo n.º 8
0
        public void RsaCryptTest()
        {
            (string pubKey, string priKey) = RSAHelper.GenRSAKeyPair();
            Console.WriteLine(pubKey);
            Console.WriteLine(priKey);

            string encyypted = RSAHelper.EncryptString(pubKey, "testsetsetset");

            Console.WriteLine(encyypted);

            var decrypt = RSAHelper.DecryptString(priKey, encyypted);

            Assert.IsTrue(decrypt == "testsetsetset");
        }
Ejemplo n.º 9
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var headers = filterContext.Request.Headers;
            var qs      = HttpUtility.ParseQueryString(filterContext.Request.RequestUri.Query);
            var uid     = Convert.ToInt32(qs["uid"] ?? "0");
            var type    = Convert.ToInt32(qs["type"] ?? "0");

            if (headers.Contains("token") && uid > 0 && type > 0)
            {
                var userType = (AuthUserType)2;
                if (type == 1)
                {
                    userType = AuthUserType.Admin;
                }
                else if (type == 2)
                {
                    userType = AuthUserType.General;
                }
                else
                {
                    filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ExceptionMessage = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckLoginAttribute_OnActionExecuting_AuthUserType") });
                }
                var tokenEncryptStr = headers.GetValues("token").First();
                var authKeys        = ((IContainer)HttpRuntime.Cache["containerKey"]).Resolve <IAuthKeysBusiness>().GetAuthKeys(uid, userType);
                if (string.IsNullOrEmpty(tokenEncryptStr) || authKeys == null || authKeys.PrivateKey == null)
                {
                    filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ExceptionMessage = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckLoginAttribute_OnActionExecuting_AuthKeys") });
                    return;
                }
                var tokenDecryptStr = RSAHelper.DecryptString(tokenEncryptStr, authKeys.PrivateKey);
                if (string.IsNullOrWhiteSpace(tokenDecryptStr) || !string.Equals(tokenDecryptStr, uid.ToString()))
                {
                    filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ExceptionMessage = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckLoginAttribute_OnActionExecuting_token") });
                    return;
                }
            }
            else
            {
                filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ExceptionMessage = LanguageUtil.Translate("api_Filters_AuthCodeAttribute_CheckLoginAttribute_OnActionExecuting_token_null") });
                return;
            }
            base.OnActionExecuting(filterContext);
        }
Ejemplo n.º 10
0
        public static bool InitConfig(RegistryKey retkey)
        {
            try
            {
                string[] retSqlNames = retkey.GetValueNames();
                foreach (string retKey in retSqlNames)
                {
                    string retVal = retkey.GetValue(retKey).ToString();
                    string key    = RSAHelper.DecryptString(retKey);
                    string val    = RSAHelper.DecryptString(retVal);
                    config.Add(key, val);
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("读取注册子信息列表失败!\n" + ex.Message);
            }

            return(false);
        }
Ejemplo n.º 11
0
        public void OnResponse_MSG_GC_BLOWFISHKEY(MemoryStream stream)
        {
            MSG_GC_BLOWFISHKEY MSG_GC_BLOWFISHKEY = MessagePacker.ProtobufHelper.Deserialize <MSG_GC_BLOWFISHKEY>(stream);
            //Parser.Parse(MSG_GC_BLOWFISHKEY);
            string rsaKey = RSAHelper.DecryptString(MSG_GC_BLOWFISHKEY.BlowfishKey, GetPublicKey());

            Net.packetHandler.BlowFishInst = new BlowFish(rsaKey);

            //if (Net.packetHandler.gettingBlowFishKey)
            //{
            //NET.GetProtocol().gettingBlowFishKey = false;
            //MSG_CG_RECONNECT_LOGIN login = new MSG_CG_RECONNECT_LOGIN();
            //login.token = PLAYER.Token;
            //login.uid = PLAYER.CurrentCharacterUid;
            //login.accountName = PLAYER.AccountName;
            //m_protocol.Send(login);
            //}

            //获取角色列表
            Request_MSG_CG_CHARACTER_LIST();
        }
Ejemplo n.º 12
0
        //判断是否已经注册
        public static bool hasReged()
        {
            try
            {
                RegistryKey retkey = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("MemTree");
                if (retkey != null)
                {
                    string mNum = retkey.GetValue("MNum").ToString();
                    string com  = retkey.GetValue("Com").ToString();
                    string usr  = retkey.GetValue("Usr").ToString();
                    if (mNum != null && com != null && usr != null)
                    {
                        Com  = RSAHelper.DecryptString(com);
                        Usr  = RSAHelper.DecryptString(usr);
                        mNum = RSAHelper.DecryptString(mNum);
                        if (mNum == getMNum())
                        {
                            RegistryKey retkeySql = retkey.OpenSubKey("SQL");
                            if (retkeySql != null)
                            {
                                if (RegConfig.InitConfig(retkeySql))
                                {
                                    return(true);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("注册码不正确!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("读取注册信息失败!\n" + ex.Message);
            }

            return(false);
        }
Ejemplo n.º 13
0
        //对注册信息文件进行解密
        private bool DecryptRegInfo(string file)
        {
            string regMsg   = EncryptHelper.FileDecrypt(file);
            int    subIndex = 1;

            disk = regMsg.Substring(0, subIndex);
            while (ContainsTimes(regMsg, disk) >= 4)
            {
                subIndex++;
                disk = regMsg.Substring(0, subIndex);
            }
            disk = regMsg.Substring(0, subIndex - 1);
            if (ContainsTimes(regMsg, disk) == 4)
            {
                string[] regList = regMsg.Split(new String[] { disk }, StringSplitOptions.RemoveEmptyEntries);
                cpu = RSAHelper.DecryptString(regList[0], privateKey);
                com = RSAHelper.DecryptString(regList[1], privateKey);
                usr = RSAHelper.DecryptString(regList[2], privateKey);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 14
0
 private void btnDecrypt_Click(object sender, EventArgs e)
 {
     if (_rsa == null)
     {
         MessageBox.Show("Please, generate a key pair first!");
         return;
     }
     if (string.IsNullOrEmpty(txtContent.Text))
     {
         MessageBox.Show("Please, inform some content!");
         return;
     }
     try
     {
         txtResult.Text = _rsa.DecryptString(txtContent.Text, txtPrivateKey.Text);
     }
     catch (Exception ex)
     {
         txtResult.Text = "";
         MessageBox.Show("There was an error trying to decrypt the text content. Check if the private key is linked with the public key used to encrypt the text content!");
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 解密
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDs_Click(object sender, EventArgs e)
 {
     txtDsed.Text = RSAHelper.DecryptString(txtSed.Text.Trim(), txtPK.Text.Trim());
 }