CheckBase64() private static méthode

private static CheckBase64 ( string value ) : bool
value string
Résultat bool
Exemple #1
0
        public static string GetNickname(string item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                var index = item.LastIndexOf('@');
                if (index == -1)
                {
                    return(null);
                }

                var nickname = item.Substring(0, index);
                var hash     = item.Substring(index + 1);

                if (nickname.Length > 256)
                {
                    return(null);
                }
                if (hash.Length > 256 || !Signature.CheckBase64(hash))
                {
                    return(null);
                }

                return(nickname);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #2
0
        public static byte[] GetHash(string item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                lock (_hashCacheLockObject)
                {
                    byte[] value;

                    if (!_hashCache.TryGetValue(item, out value))
                    {
                        var index = item.LastIndexOf('@');
                        if (index == -1)
                        {
                            return(null);
                        }

                        var nickname = item.Substring(0, index);
                        var hash     = item.Substring(index + 1);

                        if (nickname.Length > 256)
                        {
                            return(null);
                        }
                        if (hash.Length > 256 || !Signature.CheckBase64(hash))
                        {
                            return(null);
                        }

                        value = NetworkConverter.FromBase64UrlString(hash);
                        _hashCache.Add(item, value);
                    }

                    return(value);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }