473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

MD5 Hash

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
5 2619
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Murali | last post by:
I have a requirement where I have to use two unsigned ints as a key in a STL hash map. A couple of ways to do this is 1. create a struct with two unsigned ints and use that as key (write my own...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
18
by: beginner | last post by:
Hi All. I'd like to do the following in more succint code: if k in b: a=b else: a={} b=a
5
by: Jeff | last post by:
Lets say we have what I would call a "hash": var HASH =new Array(); HASH='first'; HASH='second'; HASH='third'; I'd like to return that as JSON data. Is there a direct way to do that?
1
by: sixtyfootersdude | last post by:
Good Morning! I am a perl newbie and I think that I am struggling with references. I have an array of references to hashes which I am trying to print. This is what I have: for(my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.