/// <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); }
/// <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)); }