示例#1
0
        /// <summary>
        /// Computes the FNV-1a 512-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>The FNV-1a 512-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static string Fnv1a512s(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a512())
            {
                BigInteger hash   = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero());
                string     value1 = (hash >> 256).ToString("X64", InvariantCulture);
                string     value2 = (hash & Bitmasks.Bottom64Bytes).ToString("X64", InvariantCulture);

                return("0x" + value1.Substring(value1.Length - 64) + value2.Substring(value2.Length - 64));
            }
        }
示例#2
0
        /// <summary>
        /// Asynchronously computes the FNV-1a 512-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>An asynchronous <see cref="Task{TResult}"/> containing the FNV-1a 512-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static async Task <string> Fnv1a512sAsync(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a512())
            {
                BigInteger hash   = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero());
                string     value1 = (hash >> 256).ToString("X64", InvariantCulture);
                string     value2 = (hash & Bitmasks.Bottom64Bytes).ToString("X64", InvariantCulture);

                return(await Task.FromResult("0x" + value1.Substring(value1.Length - 64) + value2.Substring(value2.Length - 64)).ConfigureAwait(false));
            }
        }