GenerateMD5Hash

Vipul
Posted by in ASP.NET category on for Beginner level | Views : 3070 red flag

These code can convert in Hash.
 
 
Introduction


This is for converting to Hash

Write Anything in Textbox and click on Compute Hash button it will generate hash value of that text.


Generate MD5 Hash

1.Create Web Application

2.Take one Web Form Give name Hash.aspx

3.Copy Following code and paste at Hash.aspx

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Security.Cryptography" %>

<script language="C#" runat=server>

byte[] Convert2ByteArray(string strInput)

{

int intCounter;

char[] arrChar;

arrChar = strInput.ToCharArray();

byte[] arrByte = new byte[arrChar.Length];

for (intCounter=0; intCounter <= arrByte.Length-1; intCounter++)

arrByte[intCounter] = Convert.ToByte(arrChar[intCounter]);

return arrByte;

}

void Button_Click( Object sender , EventArgs e ) {

byte[] arrHashInput;

byte[] arrHashOutput;

MD5CryptoServiceProvider objMD5;

objMD5 = new MD5CryptoServiceProvider();

arrHashInput = Convert2ByteArray( txtInput.Text );

arrHashOutput = objMD5.ComputeHash( arrHashInput );

lblOutput.Text = BitConverter.ToString( arrHashOutput );

}

</Script>

<html>

<head><title>Hash.aspx</title></head>

<body>

<form Runat="Server">

<h2>Generate MD5 Hash</h2>

<b>Enter text to hash:</b>

<br>

<asp:TextBox

id="txtInput"

TextMode="Multiline"

Columns="50"

Rows="10"

Runat="Server" />

<p>

<asp:Button

Text="Compute Hash!"

OnClick="Button_Click"

Runat="Server" />

<p>

<b>Hash value:</b>

<br>

<asp:Label

ID="lblOutput"

Runat="Server" />

</form>

</body>

</html>




 

Page copy protected against web site content infringement by Copyscape

About the Author

Vipul
Full Name: vipul vk
Member Level: Starter
Member Status: Member
Member Since: 4/15/2009 9:08:15 PM
Country:

http://www.dotnetfunda.com
Working as a software developer

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)