dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: .NET
Expertise: Advanced
Feb 4, 2019

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();
    }
Srinath M S
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date