示例#1
0
        /// <summary>
        ///		computes the hash code and converts it to string
        /// </summary>
        /// <param name="inputText">input text to be hashed</param>
        /// <param name="hashingType">type of hashing to use</param>
        /// <returns>hashed string</returns>
        private static string ComputeHash(string inputText, HashingTypes hashingType, EncodingTypes encodingTypes, StringFormats resultFormat)
        {
            HashAlgorithm HA          = getHashAlgorithm(hashingType);
            Encoding      textEncoder = getEncodingTypes(encodingTypes);

            //get byte representation of input text
            byte[] inputBytes = textEncoder.GetBytes(inputText);


            //hash the input byte array
            byte[] output = HA.ComputeHash(inputBytes);

            //convert output byte array to a string
            return(ConvertString(output, resultFormat));
        }
    /// <summary>
    ///     computes the hash code and converts it to string
    /// </summary>
    /// <param storeName="inputText">input text to be hashed</param>
    /// <param storeName="hashingType">type of hashing to use</param>
    /// <returns>hashed string</returns>
    private static string ComputeHash(string inputText, HashingTypes hashingType)
    {
        HashAlgorithm HA = getHashAlgorithm(hashingType);

        //declare a new encoder
        UTF8Encoding UTF8Encoder = new UTF8Encoding();

        //get byte representation of input text
        byte[] inputBytes = UTF8Encoder.GetBytes(inputText);

        //hash the input byte array
        byte[] output = HA.ComputeHash(inputBytes);

        //convert output byte array to a string
        return(Convert.ToBase64String(output));
    }
示例#3
0
        private static HashAlgorithm getHashAlgorithm(HashingTypes hashingType)
        {
            switch (hashingType)
            {
                case HashingTypes.SHA:
                    return new SHA1CryptoServiceProvider();

                case HashingTypes.SHA256:
                    return new SHA256Managed();

                case HashingTypes.SHA384:
                    return new SHA384Managed();

                case HashingTypes.SHA512:
                    return new SHA512Managed();

                case HashingTypes.MD5:
                    return new MD5CryptoServiceProvider();
            }
            return new MD5CryptoServiceProvider();
        }
示例#4
0
        /// <summary>
        ///     returns the specific hashing alorithm
        /// </summary>
        /// <param name="hashingType">type of hashing to use</param>
        /// <returns>HashAlgorithm</returns>
        private static HashAlgorithm getHashAlgorithm(HashingTypes hashingType)
        {
            switch (hashingType)
            {
            case HashingTypes.MD5:
                return(MD5.Create());

            case HashingTypes.SHA:
                return(SHA1.Create());

            case HashingTypes.SHA256:
                return(SHA256.Create());

            case HashingTypes.SHA384:
                return(SHA384.Create());

            case HashingTypes.SHA512:
                return(SHA512.Create());

            default:
                return(MD5.Create());
            }
        }
示例#5
0
        /// <summary>
        ///     returns the specific hashing alorithm
        /// </summary>
        /// <param name="hashingType">type of hashing to use</param>
        /// <returns>HashAlgorithm</returns>
        private static HashAlgorithm getHashAlgorithm(HashingTypes hashingType)
        {
            switch (hashingType)
            {
            case HashingTypes.MD5:
                return(new MD5CryptoServiceProvider());

            case HashingTypes.SHA:
                return(new SHA1CryptoServiceProvider());

            case HashingTypes.SHA256:
                return(new SHA256Managed());

            case HashingTypes.SHA384:
                return(new SHA384Managed());

            case HashingTypes.SHA512:
                return(new SHA512Managed());

            default:
                return(new MD5CryptoServiceProvider());
            }
        }
示例#6
0
		public static bool isHashEqual(string inputText, string hashText, HashingTypes hashingType)
		{
			return (Hash(inputText,hashingType) == hashText);
		}
示例#7
0
		public static string Hash(String inputText, HashingTypes hashingType)
		{
			return ComputeHash(inputText,hashingType);
		}
示例#8
0
 public static string Hash(String inputText, HashingTypes hashingType)
 {
     return(new Hashing(hashingType).ComputeHash(inputText));
 }
示例#9
0
 public Hashing(HashingTypes hashingType)
 {
     m_HashingType = hashingType;
 }
示例#10
0
 public static byte[] Hash(byte[] inputData, HashingTypes hashingType)
 {
     return(new Hashing(hashingType).ComputeHash(inputData));
 }
示例#11
0
 public static string Hash(String inputText, HashingTypes hashingType, EncodingTypes encodingTypes, StringFormats resultFormat)
 {
     return(ComputeHash(inputText, hashingType, encodingTypes, resultFormat));
 }
示例#12
0
 public static bool isHashEqual(string inputText, string hashText, HashingTypes hashingType)
 {
     return(Hash(inputText, hashingType) == hashText);
 }
示例#13
0
 public Hashing(HashingTypes hashingType)
 {
     m_HashingType = hashingType;
 }
示例#14
0
 public IPasswordHasher GetHasher(HashingTypes types) => types switch
 {
示例#15
0
 private static string ComputeHash(string inputText, HashingTypes hashingType)
 {
     HashAlgorithm algorithm = getHashAlgorithm(hashingType);
     byte[] bytes = new UTF8Encoding().GetBytes(inputText);
     return Convert.ToBase64String(algorithm.ComputeHash(bytes));
 }
示例#16
0
		/// <summary>
		///		computes the hash code and converts it to string
		/// </summary>
		/// <param name="inputText">input text to be hashed</param>
		/// <param name="hashingType">type of hashing to use</param>
		/// <returns>hashed string</returns>
		private static string ComputeHash(string inputText, HashingTypes hashingType)
		{
			HashAlgorithm HA = getHashAlgorithm(hashingType);

			//declare a new encoder
			UTF8Encoding UTF8Encoder = new UTF8Encoding();
			//get byte representation of input text
			byte[] inputBytes = UTF8Encoder.GetBytes(inputText);
			
			
			//hash the input byte array
			byte[] output = HA.ComputeHash(inputBytes);

			//convert output byte array to a string
			return Convert.ToBase64String(output);
		}
示例#17
0
 public static string Hash(String inputText, HashingTypes hashingType)
 {
     return(ComputeHash(inputText, hashingType));
 }
示例#18
0
 public static string Hash(String inputText, HashingTypes hashingType)
 {
     return new Hashing(hashingType).ComputeHash(inputText);
 }
示例#19
0
 public static byte[] Hash(byte[] inputData, HashingTypes hashingType)
 {
     return new Hashing(hashingType).ComputeHash(inputData);
 }
示例#20
0
 public static string Hash(String inputText, HashingTypes hashingType, EncodingTypes encodingTypes)
 {
     return(ComputeHash(inputText, hashingType, encodingTypes, StringFormats.BASE64));
 }