Solved

ASP.NET/VB: MD5 Hash a String

Posted on 2014-01-27
3
769 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

738 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