here is the complete tutorial
Step 1 : Include the required namespace.
using System.Security.Cryptography; using System.Text;// for stringbuilder class
using System.Security.Cryptography;
using System.Text;// for stringbuilder class
Step 2 : Create an object of MD5 class.
MD5 md5H = MD5.Create();
Step 3 : Convert the string into byte array and compute its hash
byte[] data = md5H.ComputeHash(Encoding.UTF8.GetBytes(text));
Step 4 : Loop through each byte of hashed data and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++){
sBuilder.Append(data[i].ToString("x2"));
}
complete code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
public partial class MD5Hashing : System.Web.UI.Page
{
public string MD5Hash(string text)
{
MD5 md5H = MD5.Create();
//convert the input string to a byte array and compute its hash
byte[] data = md5H.ComputeHash(Encoding.UTF8.GetBytes(text));
// create a new stringbuilder to collect the bytes and create a string
StringBuilder sB = new StringBuilder();
//loop through each byte of hashed data and format each one as a hexadecimal string
for (int i = 0; i < data.Length; i++){
sB.Append(data[i].ToString("x2"));
}
//return hexadecimal string
return sB.ToString();
}
}