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++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            return sBuilder.ToString();

        }

No comments:

Post a Comment

Testing Challenge

Can you find more than 20 defects in the below image? Write your defects in the comments section.