Solved

ASP.NET/VB: MD5 Hash a String

Posted on 2014-01-27
3
724 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
Comment Utility
0
 
LVL 4

Accepted Solution

by:
ravikantninave earned 300 total points
Comment Utility
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
Comment Utility
To get output in lowercase change in CalculteMD5Hash:

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

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now