By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

MD5 Hash

P: n/a
I found with Asp.Net, you can use this function to very easily create an MD5
hash:
System.Web.Security.FormsAuthentication.HashPasswo rdForStoringInConfigFile(
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
May 18 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Just thought, its probably useful information to know that I'm still using
2003 and the 1.1 framework.

--
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

May 18 '06 #2

P: n/a
Gary <no****@nospam.com> wrote:
I found with Asp.Net, you can use this function to very easily create an MD5
hash:
System.Web.Security.FormsAuthentication.HashPasswo rdForStoringInConfigFile(
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 18 '06 #3

P: n/a
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.T oUpper)));

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
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Gary <no****@nospam.com> wrote:
I found with Asp.Net, you can use this function to very easily create an
MD5
hash:
System.Web.Security.FormsAuthentication.HashPasswo rdForStoringInConfigFile(
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

May 18 '06 #4

P: n/a
You can use in C# the MD5 class, you can find an example at:
http://msdn2.microsoft.com/en-us/lib...raphy.md5.aspx
I used it and it work just fine ;)

May 18 '06 #5

P: n/a
Gary <no****@nospam.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.