Last active
April 10, 2018 15:32
-
-
Save VijayaMalla/95431b69003b1926981ae465a80cfb18 to your computer and use it in GitHub Desktop.
Create SHA1 Hash for a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple/Sample program to create SHA1 hash from a string.