Esempio n. 1
0
        private static string GetHashString(this string value, int size, string availableChars)
        {
            var result = default(string);

            if (!string.IsNullOrEmpty(value))
            {
                var bytes = encoding.GetBytes(value);
                var hash  = hashCreator
                            .ComputeHash(bytes).Hash;

                var hashString = new StringBuilder();

                var position = 0;
                var index    = 0;
                var length   = hash.Length - ByteLength;

                while (index <= length && position < size)
                {
                    var hashNumber = Math.Abs(BitConverter.ToInt32(
                                                  value: hash,
                                                  startIndex: index));

                    var currentChar = availableChars[hashNumber % availableChars.Length];
                    hashString.Append(currentChar);

                    index += (length - index) / (size - position);
                    position++;
                }

                result = hashString.ToString();
            }

            return(result);
        }
Esempio n. 2
0
        public Index(string index)
        {
            byte[]       byteArray = Encoding.UTF8.GetBytes(index);
            MemoryStream stream    = new MemoryStream(byteArray);

            ISpookyHashV2 spookyHash = SpookyHashV2Factory.Instance.Create();
            var           hashValue  = spookyHash.ComputeHash(stream);

            Id = hashValue.AsBase64String();
        }