ASP.NET/VB: MD5 Hash a String

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

LVL 16
Who is Participating?
ravikantninaveConnect With a Mentor Commented:
string hash = CalculateMD5Hash("abcdefghijklmnopqrstuvwxyz");
returns a string like this:


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++)
    return sb.ToString();

Open in new window

To get output in lowercase change in CalculteMD5Hash:


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.