473,903 Members | 6,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MD5 Hash

I found with Asp.Net, you can use this function to very easily create an MD5
hash:
System.Web.Secu rity.FormsAuthe ntication.HashP asswordForStori ngInConfigFile(
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 2635
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.Secu rity.FormsAuthe ntication.HashP asswordForStori ngInConfigFile(
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.G etBytes and then to convert the resulting hash back into
a string using Convert.ToBase6 4String. 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.co m>
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:

3B452D261176B79 FF70C50B6155B92 A6

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[] ConvertStringTo ByteArray(Strin g s)
{
return (new UnicodeEncoding ()).GetBytes(s) ;
}
bool checkhash(strin g original, string created)

{

MD5 md5 = new MD5CryptoServic eProvider();

md5.ComputeHash (ConvertStringT oByteArray(crea ted.ToUpper)));

string hashcreated = BitConverter.To String(md5.Hash );

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

if (hashcreated.Eq uals(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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Gary <no****@nospam. com> wrote:
I found with Asp.Net, you can use this function to very easily create an
MD5
hash:
System.Web.Secu rity.FormsAuthe ntication.HashP asswordForStori ngInConfigFile(
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.G etBytes and then to convert the resulting hash back into
a string using Convert.ToBase6 4String. 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.co m>
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:

3B452D261176B79 FF70C50B6155B92 A6


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.co m>
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
4184
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 HashFcn and EqualKey template args) or, 2. convert the two unsigned ints to char*s, concatenate them and use that as Key. For method 1, the difficulty I am having is in writing the HashFcn. HashFcn requires the following method
2
3802
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 produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
24
4324
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 these keys -- I only need to be able to retrieve the value associated with a certain key, so I do not want to have the keys stored in memory. Could I just hash() the url strings first and use the resulting integer as the key? I think what I'm...
12
7032
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
3240
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 (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
21
3924
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 applies in this case though: #include <limits.h> unsigned foo(void) { static const union { unsigned char str;
139
14284
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
1831
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
8188
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
2985
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 $i=0; $i<@input; $i++){ my $hash = $input; print "$i: \n";
0
9999
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11284
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10876
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9687
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4727
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3324
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.