Mega Code Archive

 
Categories / C# Tutorial / Security
 

Produce a SHA1 hash

using System; using System.Security.Cryptography;   class Class1   {     static void Main(string[] args)     {       string dataToHash = "this is a test";       string key = "ABCDEFGHIJKLMNOPQRSTUVWX";       byte[] dataToHash_Bytes = System.Text.Encoding.Unicode.GetBytes( dataToHash );       byte[] key_Bytes = System.Text.Encoding.ASCII.GetBytes( key );       MACTripleDES mac = new MACTripleDES( key_Bytes );              byte[] result_Bytes = mac.ComputeHash( dataToHash_Bytes );       Console.WriteLine( System.Text.Encoding.ASCII.GetString( result_Bytes ));       SHA1Managed sha1 = new SHA1Managed();       byte[] sha1_Bytes = sha1.ComputeHash( dataToHash_Bytes);       Console.WriteLine( System.Text.Encoding.ASCII.GetString( sha1_Bytes ));     }   }