Skip to content

Instantly share code, notes, and snippets.

@VijayaMalla
Last active April 10, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VijayaMalla/95431b69003b1926981ae465a80cfb18 to your computer and use it in GitHub Desktop.
Save VijayaMalla/95431b69003b1926981ae465a80cfb18 to your computer and use it in GitHub Desktop.
Create SHA1 Hash for a string
class Program
{
static void Main(string[] args)
{
var pwd = "password"; //Sample Password string
//GetBytes converts the string to byte[]
//ComputeHash computes the Hash value of the byte[]
byte[] bytes = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(pwd));
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(b.ToString("X2")); //Appends to the Stringbuilder with the formatter specified.
}
Console.WriteLine(sb); //writes the built string (final SHA1 hash representation) to console.
Console.ReadLine();
}
}
@VijayaMalla
Copy link
Author

Simple/Sample program to create SHA1 hash from a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment