public static SecurityData GetSecurityData(string securityKey)
        {
            if (string.IsNullOrWhiteSpace(securityKey))
            {
                return(null);
            }
            securityKey = Uri.UnescapeDataString(securityKey);
            string userInfo = SecurityUtility.DecryptSecurityKey(securityKey);

            string[] arr = userInfo.Split('#');

            SecurityData data = null;

            if (userInfo != null && arr.Length >= 4)
            {
                data = new SecurityData();
                DateTime expiration = DateTime.MinValue; int userId = 0; bool remember = false;
                int.TryParse(arr[0], out userId);
                DateTime.TryParse(arr[1], out expiration);
                bool.TryParse(arr[3], out remember);
                data.UserID     = userId;
                data.Expiration = expiration;
                data.UserData   = SecurityUtility.DecryptUserData(Uri.UnescapeDataString(arr[2]));
                data.Remember   = remember;
                data.UserPhone  = arr.Length >= 5 ? arr[4] : "";
                data.UserName   = arr.Length >= 6 ? arr[5] : "";
            }
            return(data);
        }
        /// <summary>
        /// BDapp-GetBdSecurityData
        /// </summary>
        /// <param name="securityKey"></param>
        /// <returns></returns>
        public static BdSecurityData GetBdSecurityData(string securityKey)
        {
            if (string.IsNullOrWhiteSpace(securityKey))
            {
                return(null);
            }

            securityKey = Uri.UnescapeDataString(securityKey);
            string userInfo = SecurityUtility.DecryptSecurityKey(securityKey);

            string[] arr = userInfo.Split('#');

            BdSecurityData data = null;

            if (userInfo != null && arr.Length >= 4)
            {
                data = new BdSecurityData();
                DateTime expiration = DateTime.MinValue; int userId = 0; bool remember = false;
                int.TryParse(arr[0], out userId);
                DateTime.TryParse(arr[1], out expiration);
                bool.TryParse(arr[3], out remember);
                data.UserID       = userId;
                data.Expiration   = expiration;
                data.UserData     = SecurityUtility.DecryptUserData(Uri.UnescapeDataString(arr[2]));
                data.Remember     = remember;
                data.UserPhone    = arr.Length >= 5 ? arr[4] : "";
                data.UserName     = arr.Length >= 6 ? arr[5] : "";
                data.Agent        = arr.Length >= 7 ? arr[6] : "";
                data.Roles        = arr.Length >= 8 ? JsonConvert.DeserializeObject <List <int> >(arr[7]) : new List <int>();
                data.LoginAccount = arr.Length >= 9 ? arr[8] : "";
            }
            return(data);
        }
        public static string GetSecurityKey(SecurityData data)
        {
            string userdata = Uri.EscapeDataString(SecurityUtility.EncryptUserData(data.UserData));
            string input    = string.Format("{0}#{1}#{2}#{3}#{4}#{5}", data.UserID, data.Expiration, userdata, data.Remember, data.UserPhone, data.UserName);
            string key      = SecurityUtility.EncryptSecurityKey(input);

            //base on http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx
            return(Uri.EscapeDataString(key));
        }
        /// <summary>
        /// BDapp-GetBdSecurityKey
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string GetBdSecurityKey(BdSecurityData data)
        {
            string userdata = Uri.EscapeDataString(SecurityUtility.EncryptUserData(data.UserData));
            string input    = string.Format(
                "{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7}#{8}",
                data.UserID,
                data.Expiration,
                userdata,
                data.Remember,
                data.UserPhone,
                data.UserName,
                data.Agent,
                JsonConvert.SerializeObject(data.Roles),
                data.LoginAccount);
            string key = SecurityUtility.EncryptSecurityKey(input);

            return(Uri.EscapeDataString(key));
        }
 public static string RefeshSecurityKey(SecurityData securityData)
 {
     securityData.Expiration = SecurityUtility.GetExpiration(securityData.Remember);
     return(SecurityUtility.GetSecurityKey(securityData));
 }