/// <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)); }
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(); }
/// <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()); } }
/// <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()); } }
public static bool isHashEqual(string inputText, string hashText, HashingTypes hashingType) { return (Hash(inputText,hashingType) == hashText); }
public static string Hash(String inputText, HashingTypes hashingType) { return ComputeHash(inputText,hashingType); }
public static string Hash(String inputText, HashingTypes hashingType) { return(new Hashing(hashingType).ComputeHash(inputText)); }
public Hashing(HashingTypes hashingType) { m_HashingType = hashingType; }
public static byte[] Hash(byte[] inputData, HashingTypes hashingType) { return(new Hashing(hashingType).ComputeHash(inputData)); }
public static string Hash(String inputText, HashingTypes hashingType, EncodingTypes encodingTypes, StringFormats resultFormat) { return(ComputeHash(inputText, hashingType, encodingTypes, resultFormat)); }
public static bool isHashEqual(string inputText, string hashText, HashingTypes hashingType) { return(Hash(inputText, hashingType) == hashText); }
public IPasswordHasher GetHasher(HashingTypes types) => types switch {
private static string ComputeHash(string inputText, HashingTypes hashingType) { HashAlgorithm algorithm = getHashAlgorithm(hashingType); byte[] bytes = new UTF8Encoding().GetBytes(inputText); return Convert.ToBase64String(algorithm.ComputeHash(bytes)); }
/// <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); }
public static string Hash(String inputText, HashingTypes hashingType) { return(ComputeHash(inputText, hashingType)); }
public static string Hash(String inputText, HashingTypes hashingType) { return new Hashing(hashingType).ComputeHash(inputText); }
public static byte[] Hash(byte[] inputData, HashingTypes hashingType) { return new Hashing(hashingType).ComputeHash(inputData); }
public static string Hash(String inputText, HashingTypes hashingType, EncodingTypes encodingTypes) { return(ComputeHash(inputText, hashingType, encodingTypes, StringFormats.BASE64)); }