Sunday, January 4, 2009

To Build an MD5 encrypted password in C#

   Md5 is a good algorithm for securing your passwords
thanks to .net that it has a wonderful namespace  System.Web.Security which contains built-in functions for all well known security algorithms.
The code to obatain an MD5 encrypted string from any given input is as follows.  

  public string getmd5hash(string input)
            MD5 md5hasher = MD5.Create();
            byte[] data = md5hasher.ComputeHash(Encoding.Default.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)

            return sBuilder.ToString();


1 comment:

  1. Md5 is really good at securing passwords, but I had some hardships implementing it, and your post made this process clear for me.