SHA1 C# with Example



SHA1 C# with Example

using System; 
using System.Security.Cryptography; 
using System.Text; 
namespace ConsoleApplication1 
{ 
class Program 
{ 
 

static void Main(string[] args) 
{ 
string source = "Hello World!"; 
using (SHA1 sha1Hash = SHA1.Create()) 
{ 
//From String to byte array 
byte[] sourceBytes = Encoding.UTF8.GetBytes(source); 
byte[] hashBytes = sha1Hash.ComputeHash(sourceBytes); 
string hash = BitConverter.ToString(hashBytes).Replace("-",String.Empty); 
Console.WriteLine("The SHA1 hash of " + source + " is: " + hash); 
} 
} 
} 
} 
Output: 
The SHA1 hash of Hello Word! is: 2EF7BDE608CE5404E97D5F042F95F89F1C232871 

0 Comment's

Comment Form

Submit Comment