How to convert original text to hash text using md5 and sh1 Algorithms in asp.net c#

By
Introduction:- Hashing is secure and helpful concepts to convert original text to hash text.It is a cryptography Technology.There are many cryptography technology such symmetric and asymmetric but here we will learn only hashing concepts (md5 and sh1).If you want to discuss more details about cryptography ,you can contact me(holiday only).
  • A Hash function is an Algorithm which creates a digital representation or 'fingerprint' in the form of a "hash value" of a standard length.
  • Hash value is usually much smaller than the message.
  • It is one way function.
MD5  Hash Algorithm:-
  • MD5 is a message digest technology developed by  Ronald Rivest .
  • Processing input text in 512 bit block.
  • Output size 128 bit.
SH1  Hash Algorithm:-
  • SHA  means secure hash Algorithm.
  • It produces 160 bit hash value.
  • Nowadays,It is using more preferred algorithm
There are some steps to implement this whole concepts in asp.net website. 
Step 1:- First open your visual studio-->File --> New --> Website--> Select ASP.NET Empty Website-->OK--> add Default.aspx page  in Solution Explorer Window--> Drag and TextBox ,Label and button control on the page as shown below:-

Step 2:- Write the c# codes inside each button handlers as given below:-
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        byte[] hs = new byte[50];
     string pass=TextBox1.Text;   
     MD5 md5 = MD5.Create();
     byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(pass);
     byte[] hash = md5.ComputeHash(inputBytes);
        StringBuilder sb = new StringBuilder();
     for (int i = 0; i < hash.Length; i++)
      {
          hs[i] = hash[i];  
        sb.Append(hs[i].ToString("x2"));
      }
       Label1.Text = sb.ToString();
      }
    protected void Button2_Click(object sender, EventArgs e)
    {
         byte[] hs1 = new byte[50];
        string pass1=TextBox1.Text;  
        SHA1 sh = SHA1.Create();
         byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(pass1);
     byte[] hash1 = sh.ComputeHash(inputBytes);
        StringBuilder sb = new StringBuilder();
     for (int i = 0; i < hash1.Length; i++)
      {
          hs1[i] = hash1[i];  
        sb.Append(hs1[i].ToString("x2"));
      }
     Label1.Text = sb.ToString();
    }    
}

Step 3:- Now Run the Application(Press F5)--> You will see following output as shown below:-

Step 4:- You can convert your original text to hash text online--> Go http://msdotnet.somee.com/  as shown below:-

For More...
Download whole Attached file
      Download

1 comment:

  1. how-to-make-registration-and-login-form.in c sharp

    ReplyDelete

Powered by Blogger.