How to Create a Hash String for a String Input

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

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist