Ejemplo n.º 1
0
        /// <summary>
        ///     Create new Datahasher with given algorithm
        /// </summary>
        /// <param name="algorithm">Hash algorithm</param>
        public DataHasher(HashAlgorithm algorithm)
        {
            if (algorithm == null)
            {
                throw new ArgumentNullException(nameof(algorithm));
            }

            _algorithm = algorithm;
            _hasher    = GetHasher(algorithm);
        }
Ejemplo n.º 2
0
 private static HMAC GetHasher(HashAlgorithm hmacAlgorithm, byte[] key)
 {
     if (hmacAlgorithm == HashAlgorithm.Sha1)
     {
         return(new HMACSHA1(key));
     }
     if (hmacAlgorithm == HashAlgorithm.Sha2256)
     {
         return(new HMACSHA256(key));
     }
     if (hmacAlgorithm == HashAlgorithm.Ripemd160)
     {
         return(new HMACRIPEMD160(key));
     }
     if (hmacAlgorithm == HashAlgorithm.Sha2384)
     {
         return(new HMACSHA384(key));
     }
     if (hmacAlgorithm == HashAlgorithm.Sha2512)
     {
         return(new HMACSHA512(key));
     }
     throw new HashingException("Hash algorithm(" + hmacAlgorithm.Name + ") is not supported.");
 }
Ejemplo n.º 3
0
 private static System.Security.Cryptography.HashAlgorithm GetHasher(HashAlgorithm algorithm)
 {
     if (algorithm == HashAlgorithm.Sha1)
     {
         return(new SHA1CryptoServiceProvider());
     }
     if (algorithm == HashAlgorithm.Sha2256)
     {
         return(new SHA256Managed());
     }
     if (algorithm == HashAlgorithm.Ripemd160)
     {
         return(new RIPEMD160Managed());
     }
     if (algorithm == HashAlgorithm.Sha2384)
     {
         return(new SHA384Managed());
     }
     if (algorithm == HashAlgorithm.Sha2512)
     {
         return(new SHA512Managed());
     }
     throw new HashingException("Hash algorithm(" + algorithm.Name + ") is not supported.");
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create new HmacHasher with given algorithm
 /// </summary>
 /// <param name="algorithm">HMAC algorithm</param>
 public HmacHasher(HashAlgorithm algorithm)
 {
     _algorithm = algorithm;
 }