dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: How to Create a Hash String for a String Input

See how to use the SHA1Managed class and compute hash for an input string.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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

 

Visit the DevX Tip Bank

 





   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Thanks for your registration, follow us on our social networks to keep up-to-date