Generate SHA1 Hash from string

Posted on: Tue Sep 08 12:10:54 -0700 2009. Updated on: Tue Sep 08 12:13:24 -0700 2009.
Category: DotNet

Code to one way hash a string using SHA1.

public static string GenerateSHA1(string input)
{
    byte[] buffer = Encoding.UTF8.GetBytes(input);
    SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
    string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

    return hash;
}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.