How do I calculate a MD5 hash from a string?

Hi

Yesterday when i am working on one of my ASP application in which we store the password as MD5 hash in database ..   when i trying to make the Application in C# . I felt diffuclut to convert the password string to MD5 Hash ( which is a 32-character string of hexadecimal numbers).  

Then i found a way in asp.net 2.0 we have a namespace called System.Security.Cryptography  in the we have the MD5 Hash function .. here is the code to covert string to MD5 Hash

public string CalculateMD5Hash(string input)
{
    // step 1, calculate MD5 hash from input
    MD5 md5 = System.Security.Cryptography.MD5.Create();
    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    byte[] hash = md5.ComputeHash(inputBytes);

    // step 2, convert byte array to hex string
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hash.Length; i++)
    {
        sb.Append(hash[i].ToString(”X2″));
    }
    return sb.ToString();
}
An example call:

string hash = CalculateMD5Hash(”abcdefghijklmnopqrstuvwxyz”);…returns a string like this:

C3FCD3D76192E4007DFB496CCA67E13BTo make the hex string use lower-case letters instead of upper-case, replace the single line inside the for loop with this line:

sb.Append(hash[i].ToString(”x2″));The difference is the ToString method parameter

Regards,
Elam

Add a loading image to UpdateProgress Control

Hi
Yesterday when I am coming across the Asp.net Ajax.. I found the control UpdateProgress . It’s quite easy and good to show the progress images. To add an image like a rotating circle or moving bar to the UpdateProgress Control is super easy.  Go to: http://www.ajaxload.info/ and generate the type of image you would like to display.  Click download image and the image will then be displayed in the browser. Right click on the image and save image to your image folder.  

After that just drag the UpdateProgress to the designer view and then get the image Control and the put it inside the update progress control. Then go to image control property and then add the image URL path…  and also you can add the time to DisplayAfter. 

All done now..
Elam

Tag cloud widget powered by nktagcloud