Beispiel #1
0
        /// <summary>
        /// Computes the FNV-1a 128-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>The FNV-1a 128-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static string Fnv1a128s(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a128())
            {
                string value = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero()).ToString("X32", InvariantCulture);

                return("0x" + value.Substring(value.Length - 32));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously computes the FNV-1a 128-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>An asynchronous <see cref="Task{TResult}"/> containing the FNV-1a 128-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static async Task <string> Fnv1a128sAsync(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a128())
            {
                string value = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero()).ToString("X32", InvariantCulture);

                return(await Task.FromResult("0x" + value.Substring(value.Length - 32)).ConfigureAwait(false));
            }
        }