Beispiel #1
0
 /// <summary>
 /// Computes the Hash of the given <see cref="IHashable"/> input.
 /// </summary>
 /// <typeparam name="H">The <see cref="HashAlgorithm"/> to use.</typeparam>
 /// <param name="input">The <see cref="IHashable"/> to compute the hash of.</param>
 /// <param name="hashingOptions">The options to use to compte the Hash.</param>
 /// <returns></returns>
 public static HashResult <H> Hash <H>(this IHashable input, HashingOptions hashingOptions = null)
     where H : HashAlgorithm, new()
 {
     if (input == null)
     {
         throw new ArgumentNullException(nameof(input));
     }
     return(new HashResult <H>(input, hashingOptions));
 }
        /// <summary>
        /// Create an <see cref="HashResult{H}"/>
        /// </summary>
        /// <param name="input">the object from which the hash is to be calculated.</param>
        /// <param name="hashingOptions">Optional. Options to change the behaviour of the <see cref="HashResult{H}"/>.</param>
        public HashResult(IHashable input, HashingOptions hashingOptions = null)
        {
            #region HashingOptions Management
            if (hashingOptions is null)
            {
                hashingOptions = HashingOptions.DefaultHashingOptions;
            }
            #endregion

            LazyHash = new Lazy <byte[]>(() => input.GetBytesForHash().Hash <H>());

            LazyStringValue = new Lazy <string>(() => ToString(HashingOptions.Separator, HashingOptions.Format), true);
        }
 /// <summary>
 /// Compute the <see cref="SHA256"/> Hash with of the given <see cref="IHashable"/>.
 /// </summary>
 /// <param name="input">The <see cref="IHashable"/> to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <returns></returns>
 public static HashResult <SHA256CryptoServiceProvider> Sha256(this IHashable input, HashingOptions hashingOptions = null)
 => input.Hash <SHA256CryptoServiceProvider>(hashingOptions);
 /// <summary>
 /// Compute the <see cref="SHA256"/> Hash with of the given <see cref="string"/>.
 /// </summary>
 /// <param name="input">The <see cref="string"/> to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <param name="stringEncoding">Optional. The encoding of the input <see cref="string"/>,
 /// used to convert the <see cref="string"/> into an array of bytes.</param>
 /// <returns></returns>
 public static HashResult <SHA256CryptoServiceProvider> Sha256(this string input, HashingOptions hashingOptions = null, Encoding stringEncoding = null)
 => input.ToHashable(stringEncoding).Sha256(hashingOptions);
 /// <summary>
 /// Compute the <see cref="SHA256"/> Hash with of the given array of bytes.
 /// </summary>
 /// <param name="input">The array of bytes to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <returns></returns>
 public static HashResult <SHA256CryptoServiceProvider> Sha256(this byte[] input, HashingOptions hashingOptions = null)
 => input.ToHashable().Sha256(hashingOptions);
Beispiel #6
0
 /// <summary>
 /// Compute the <see cref="System.Security.Cryptography.MD5"/> Hash with of the given <see cref="IHashable"/>.
 /// </summary>
 /// <param name="input">The <see cref="IHashable"/> to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <returns></returns>
 public static HashResult <MD5CryptoServiceProvider> MD5(this IHashable input, HashingOptions hashingOptions = null)
 => input.Hash <MD5CryptoServiceProvider>(hashingOptions);
Beispiel #7
0
 /// <summary>
 /// Compute the <see cref="System.Security.Cryptography.MD5"/> Hash with of the given <see cref="string"/>.
 /// </summary>
 /// <param name="input">The <see cref="string"/> to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <param name="stringEncoding">Optional. The encoding of the input <see cref="string"/>,
 /// used to convert the <see cref="string"/> into an array of bytes.</param>
 /// <returns></returns>
 public static HashResult <MD5CryptoServiceProvider> MD5(this string input, HashingOptions hashingOptions = null, Encoding stringEncoding = null)
 => input.ToHashable(stringEncoding).MD5(hashingOptions);
Beispiel #8
0
 /// <summary>
 /// Compute the <see cref="System.Security.Cryptography.MD5"/> Hash with of the given array of bytes.
 /// </summary>
 /// <param name="input">The array of bytes to calculate the hash of.</param>
 /// <param name="hashingOptions">Optional. Options to change the behaviour of the hashing computation.</param>
 /// <returns></returns>
 public static HashResult <MD5CryptoServiceProvider> MD5(this byte[] input, HashingOptions hashingOptions = null)
 => input.ToHashable().MD5(hashingOptions);