Mega Code Archive

 
Categories / C# / Security
 

Generates a hash code of the input string

using System; using System.Text;     public enum HashType     {         SHA1,         MD5,         SHA256,         SHA384,         SHA512     }     public static class EncryptionUtils     {         public static string HashString(string clearText, HashType hashType)         {             var algorithm = System.Security.Cryptography.HashAlgorithm.Create(hashType.ToString());             var encodedBytes = algorithm.ComputeHash(Encoding.Unicode.GetBytes(clearText));             return Convert.ToBase64String(encodedBytes);         }     } }