Пример #1
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary>
        /// Creates the hash.
        /// </summary>
        /// <remarks>
        /// LM ANWAR, 6/2/2013.
        /// </remarks>
        /// <param name="mode">
        /// The mode.
        /// </param>
        /// <param name="inputBytes">
        /// The input in bytes.
        /// </param>
        /// <param name="saltBytes">
        /// The salt in bytes.
        /// </param>
        /// <returns>
        /// String as Hash.
        /// </returns>
        /// -------------------------------------------------------------------------------------------------
        public static string CreateHash(KeyedHashMode mode, byte[] inputBytes, byte[] saltBytes)
        {
            var hashAlgorithm = CreateKeyedHashAlgorithm(mode, saltBytes);

            byte[]        data    = hashAlgorithm.ComputeHash(inputBytes);
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                builder.Append(data[i].ToString("x2"));
            }

            return(builder.ToString());
        }
Пример #2
0
        private static HashAlgorithm CreateKeyedHashAlgorithm(KeyedHashMode mode, byte[] key)
        {
            switch (mode)
            {
            case KeyedHashMode.HMACMD5:
                return(new HMACMD5(key));

            case KeyedHashMode.HMACSHA1:
                return(new HMACSHA1(key));

            case KeyedHashMode.MACTripleDES:
                return(new MACTripleDES(key));

            default:
                goto case KeyedHashMode.HMACMD5;
            }
        }