Exemple #1
0
 /// <summary>
 /// 从GUID中解析出服务器ID,创建时间,值
 /// </summary>
 /// <param name="guid"></param>
 /// <param name="serverId"></param>
 /// <param name="createTime"></param>
 /// <returns></returns>
 public static long DecryptGUID(string guid, out int serverId, out DateTime createTime)
 {
     long[] vv = hashIds.DecodeLong(guid);
     if (vv == null || vv.Length < 2)
     {
         serverId   = 0;
         createTime = new DateTime(0);
         return(0);
     }
     serverId   = (int)vv[0];
     createTime = new DateTime(vv[1], DateTimeKind.Utc).AddYears(2018);
     return(vv[1]);
 }
Exemple #2
0
        public UserCache GetUserCache(string token)
        {
            UserCache user      = null;
            var       validator = new JwtSecurityTokenHandler();
            var       jwtToken  = validator.ReadJwtToken(token);
            var       userClaim = jwtToken.Claims.FirstOrDefault(ww => ww.Type == "userId");

            if (userClaim != null)
            {
                string hashCode = userClaim.Value;
                var    hashIds  = new HashidsNet.Hashids(salt: Salt.IdSalt);
                var    data     = hashIds.DecodeLong(hashCode);
                long   userId   = Convert.ToInt64(data[1]);
                user = GetUserCache(userId);
            }
            return(user);
        }
Exemple #3
0
 public void RoundtripLongs()
 {
     var encodedValue = _hashids.EncodeLong(_longs);
     var decodedValue = _hashids.DecodeLong(encodedValue);
 }