Generates a hash code of the input string : Hash « Security « C# / C Sharp






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);
        }
    }
}

   
  








Related examples in the same category

1.Verify Hex Hash, Base64 Hash, Byte Hash
2.Generic Hash
3.Get Public Key Hash with HttpClientCertificate
4.Get Public Key Hash with SHA256
5.Get Public Key Hash for a string
6.Hash As Password
7.Generate Hash
8.Get Hash for password
9.Hash Data
10.Hash Password
11.Get SHA256 Hash
12.Create Password Hash