Esempio n. 1
0
        /// <summary>
        /// Token验证
        /// </summary>
        /// <param name="token"></param>
        /// <returns>true:验证通过,false:验证失败</returns>
        public bool ValidateToken(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(false);
            }
            var tokenObj = EncryptUtil.AesDecrypt(token);

            if (!string.IsNullOrEmpty(tokenObj))
            {
                var strs = tokenObj.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (strs.Length == 2)
                {
                    var      createOn = strs[1];
                    DateTime createOnDate;
                    if (DateTime.TryParse(createOn, out createOnDate))
                    {
                        var expireMinutes = System.Configuration.ConfigurationManager.AppSettings["SessionExpireMinutes"] ?? "120";
                        if (createOnDate.AddMinutes(double.Parse(expireMinutes)) > DateTime.Now)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        protected override void Initialize()
        {
            var users = _context.Set <Employee>().ToList();

            foreach (var user in users)
            {
                var passwordText = EncryptUtil.AesDecrypt(user.Password);
                if (!string.IsNullOrEmpty(passwordText))
                {
                    user.Password = EncryptUtil.Md5Hash(passwordText);
                }
            }
        }
Esempio n. 3
0
    static int AesDecrypt(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <byte[]>(L, 2))
            {
                EncryptUtil obj  = (EncryptUtil)ToLua.CheckObject <EncryptUtil>(L, 1);
                byte[]      arg0 = ToLua.CheckByteBuffer(L, 2);
                byte[]      o    = obj.AesDecrypt(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <string>(L, 2))
            {
                EncryptUtil obj  = (EncryptUtil)ToLua.CheckObject <EncryptUtil>(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                string      o    = obj.AesDecrypt(arg0);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <byte[], string>(L, 2))
            {
                EncryptUtil obj  = (EncryptUtil)ToLua.CheckObject <EncryptUtil>(L, 1);
                byte[]      arg0 = ToLua.CheckByteBuffer(L, 2);
                string      arg1 = ToLua.ToString(L, 3);
                byte[]      o    = obj.AesDecrypt(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, string>(L, 2))
            {
                EncryptUtil obj  = (EncryptUtil)ToLua.CheckObject <EncryptUtil>(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                string      arg1 = ToLua.ToString(L, 3);
                string      o    = obj.AesDecrypt(arg0, arg1);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: EncryptUtil.AesDecrypt"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }