MD5 Hash

G

Gary

I found with Asp.Net, you can use this function to very easily create an MD5
hash:
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
created.ToUpper(),"MD5");

Is there a similar one for Windows programs? I like that function because
you don't have to convert to bytes. The variable created is simply a string
which makes life easy. :) I tried using it in a windows program but it
didn't like it :?
--
Need Software? Beaver Valley Software might be able to help
http://www.beavervalleysoftware.com

Develop Software? Join the Association of Independent Software Industry
Professionals
http://www.aisip.com
 
J

Jon Skeet [C# MVP]

Gary said:
I found with Asp.Net, you can use this function to very easily create an MD5
hash:
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
created.ToUpper(),"MD5");

Is there a similar one for Windows programs? I like that function because
you don't have to convert to bytes. The variable created is simply a string
which makes life easy. :) I tried using it in a windows program but it
didn't like it :?

It's really not that hard to convert a string into bytes using (say)
Encoding.UTF8.GetBytes and then to convert the resulting hash back into
a string using Convert.ToBase64String. If you want to encapsulate that
in a method, feel free to do so - it would only be about 3 lines of
code.
 
G

Gary

Actually I haven't been able to get the functions that use bytes to produce
a true MD5 Hash in a windows program.

I had written the below function to check a hash. Instead of producing a MD5
hash it produced:
69-97-3C-07-7A-43-AE-B1-78-3B-72-67-D6-E3-F1-C9

It was supposed to be:

3B452D261176B79FF70C50B6155B92A6

I never figured out why and it just happened that I was doing a web app and
found the other function that didn't include converting into bytes.

Sorry about the formatting. Its from an email that I sent but its based on
the c# sample code that came with VS. I hope someone notices what I'm doing
wrong because I'd like to use hashes in my windows app to protect the
license key better against decompilers.

public static Byte[] ConvertStringToByteArray(String s)
{
return (new UnicodeEncoding()).GetBytes(s);
}


bool checkhash(string original, string created)

{

MD5 md5 = new MD5CryptoServiceProvider();

md5.ComputeHash(ConvertStringToByteArray(created.ToUpper)));

string hashcreated = BitConverter.ToString(md5.Hash);

Response.Write("<BR>HASH: "+hashcreated+"<br>");

if (hashcreated.Equals(original))

return true;

else

return false;

}


--
Need Software? Beaver Valley Software might be able to help
http://www.beavervalleysoftware.com

Develop Software? Join the Association of Independent Software Industry
Professionals
http://www.aisip.com
 
J

Jon Skeet [C# MVP]

Gary said:
Actually I haven't been able to get the functions that use bytes to produce
a true MD5 Hash in a windows program.

I had written the below function to check a hash. Instead of producing a MD5
hash it produced:
69-97-3C-07-7A-43-AE-B1-78-3B-72-67-D6-E3-F1-C9

It was supposed to be:

3B452D261176B79FF70C50B6155B92A6

What do you mean by "supposed to be"? What generated that hash code?
Note that although MD5 is "standard", that operates on binary data, not
text - so you need to know how whatever generated that code converted
the text into binary data to start with. For instance, it could have
used a different encoding, or included a terminating null at the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top