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