Produce a SHA1 hash : SHA1Managed « Security « C# / CSharp Tutorial






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 ));

    }
  }








35.11.SHA1Managed
35.11.1.Generate the hash code of the file's contents
35.11.2.Generate the hash code of the password
35.11.3.Produce a SHA1 hash