Solved

ASP.NET/VB: MD5 Hash a String

Posted on 2014-01-27
3
737 Views
Last Modified: 2014-01-27
Using ASP.NET/VB, I want to be able to use MD5 to hash a string like this:
response.write(md5("Hello World"))

Open in new window

0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 200 total points
ID: 39812986
0
 
LVL 4

Accepted Solution

by:
ravikantninave earned 300 total points
ID: 39812987
string hash = CalculateMD5Hash("abcdefghijklmnopqrstuvwxyz");
returns a string like this:

C3FCD3D76192E4007DFB496CCA67E13B

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();
}

Open in new window

0
 
LVL 4

Expert Comment

by:ravikantninave
ID: 39813004
To get output in lowercase change in CalculteMD5Hash:

sb.Append(hash[i].ToString("x2"));

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question