Sunday, April 27, 2008

MD5 CryptoServiceProvider using C#

This class used to create a function Encrypt the Password.
Just put it this way,Whenever the user login into password protected pages of the website,their password first undergo the MD5 Algorithm based conversion.
Then converted or encrypted password check their identification on the stored data.
If both are matched,we allow the user to navigate the login protected pages.

This password can be crack down once the hacker using the dictionary attack if your database compromised by the hacker.

We can overcome this ,by using salting concept.

Salting means just before generating the hash of a text, we attach a piece of random string – known as a salt - into the original text.

using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Web;
using System.Security.Cryptography;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// Summary description for Murugesan

public class Murugesan
public Murugesan()


public string MuruDate(DateTime d)
d = d.AddDays(2);
string DateAddS = d.ToLongDateString();
return DateAddS;


public string Encrypt(string text)
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] p = UnicodeEncoding.UTF8.GetBytes(text);
byte[] en = md5.ComputeHash(p);
return Convert.ToBase64String(en);