Generate a MD5 Encrypted Value in C#

I don't know what your problem is, but I'll bet it's hard to pronounce.

Generate a MD5 Encrypted Value in C#

Postby ShiftPoint » Sun Jul 05, 2009 9:12 pm

I had to create a method to generate a MD5 encrypted value based on a text field in C#. I used this to generate the string that I have to pass to a php page.


Code: Select all
   string urlString = MD5Encrypt(this.Password.ToString());

    public static string MD5Encrypt(string valueString)

     {

         string ret = String.Empty;

         //Setup crypto

         MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

         //Get bytes

         byte[] data = System.Text.Encoding.ASCII.GetBytes(valueString);

         //Encrypt

         data = md5Hasher.ComputeHash(data);

         //Convert from byte 2 hex

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

         {

             ret += data[i].ToString("x2").ToLower();

         }

         //Return encoded string

         return ret;



     }
User avatar
ShiftPoint
 
Posts: 70
Joined: Sun Jul 05, 2009 4:52 pm
Location: Pickerington, OH

Return to ASP.Net

Who is online

Users browsing this forum: No registered users and 0 guests