How to Create a Hash String for a String Input

You can use the SHA1Managed class and compute hash for an input string as shown below.

It is done in two steps. First, is to get the byte array after computation, and second is converting the bytes into string and append them.

Using (SHA1Managed sha1 = new SHA1Managed())   {        var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(inputstring));        var hashSB = new StringBuilder(hash.Length * 2);        foreach (byte b in hash)        {                hashSB.Append(b.ToString(???x2???));        }        return sb.ToString();    }
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: