473,486 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting MD5 of EXE

Hi,

I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it to the
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-c kinda helps, but i am
still stuck.

Thanks,
Jason
Jul 10 '08 #1
8 3817
On Jul 10, 3:06*pm, greatbarrier86
<greatbarrie...@discussions.microsoft.comwrote:
I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it tothe
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-ckinda helps, but i am
still stuck.
Open the file as a stream, and call MD5.ComputeHash.

Jon
Jul 10 '08 #2
Jason,

Take a look at the MD5Cng or the MD5CryptoServiceProvider classes in the
System.Security.Cryptography namespace. Basically, you will open a
FileStream for the EXE file and pass that to the ComputeHash method on the
instance of the object. It will return the bytes representing the hash,
which you can compare to your stored value.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"greatbarrier86" <gr************@discussions.microsoft.comwrote in message
news:07**********************************@microsof t.com...
Hi,

I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it to
the
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-c kinda helps, but i am
still stuck.

Thanks,
Jason

Jul 10 '08 #3
I'm just starting out here so i need a little more help, if you don't mind.
Also, does the passed in argument have to be converted too?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Jason,

Take a look at the MD5Cng or the MD5CryptoServiceProvider classes in the
System.Security.Cryptography namespace. Basically, you will open a
FileStream for the EXE file and pass that to the ComputeHash method on the
instance of the object. It will return the bytes representing the hash,
which you can compare to your stored value.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"greatbarrier86" <gr************@discussions.microsoft.comwrote in message
news:07**********************************@microsof t.com...
Hi,

I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it to
the
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-c kinda helps, but i am
still stuck.

Thanks,
Jason


Jul 10 '08 #4
greatbarrier86 wrote:
I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it to the
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-c kinda helps, but i am
still stuck.
Try:

public static string MD5(string fnm)
{
HashAlgorithm md5 = new MD5CryptoServiceProvider();
using(Stream f = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
{
byte[] b = new byte[100000];
byte[] garbage = new byte[100000];
int n;
while((n = f.Read(b, 0, b.Length)) 0)
{
md5.TransformBlock(b, 0, n, garbage, 0);
}
md5.TransformFinalBlock(b, 0, 0);
return BitConverter.ToString(md5.Hash).Replace("-", "");
}
}

but MD5 is not good any longer, so I will actually
recommend SHA256 instead:

public static string SHA256(string fnm)
{
HashAlgorithm sha256 = new SHA256Managed();
using(Stream f = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
{
byte[] b = new byte[100000];
byte[] garbage = new byte[100000];
int n;
while((n = f.Read(b, 0, b.Length)) 0)
{
sha256.TransformBlock(b, 0, n, garbage, 0);
}
sha256.TransformFinalBlock(b, 0, 0);
return BitConverter.ToString(sha256.Hash).Replace("-", "");
}
}

Arne
Jul 14 '08 #5
greatbarrier86 wrote:
I'm completely stumped on this but i want to create something that can get
the md5 value of an EXE based on the passed in argument and compare it to the
specified MD5.

I can do the comparison, but i dont know how to get the EXE md5 value. Can
someone help?

http://www.howforge.com/how-to-calculate-md5-in-c kinda helps, but i am
still stuck.
Try:

public static string MD5(string fnm)
{
HashAlgorithm md5 = new MD5CryptoServiceProvider();
using(Stream f = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
{
byte[] b = new byte[100000];
byte[] garbage = new byte[100000];
int n;
while((n = f.Read(b, 0, b.Length)) 0)
{
md5.TransformBlock(b, 0, n, garbage, 0);
}
md5.TransformFinalBlock(b, 0, 0);
return BitConverter.ToString(md5.Hash).Replace("-", "");
}
}

but MD5 is not good any longer, so I will actually
recommend SHA256 instead:

public static string SHA256(string fnm)
{
HashAlgorithm sha256 = new SHA256Managed();
using(Stream f = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
{
byte[] b = new byte[100000];
byte[] garbage = new byte[100000];
int n;
while((n = f.Read(b, 0, b.Length)) 0)
{
sha256.TransformBlock(b, 0, n, garbage, 0);
}
sha256.TransformFinalBlock(b, 0, 0);
return BitConverter.ToString(sha256.Hash).Replace("-", "");
}
}

Arne
Jul 14 '08 #6
On Jul 14, 3:41*am, Arne Vajhøj <a...@vajhoej.dkwrote:
Try:

* * * * *public static string MD5(string fnm)
* * * * *{
* * * * * * *HashAlgorithm md5 = new MD5CryptoServiceProvider();
* * * * * * *using(Stream f = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
* * * * * * *{
* * * * * * * * *byte[] b = new byte[100000];
* * * * * * * * *byte[] garbage = new byte[100000];
* * * * * * * * *int n;
* * * * * * * * *while((n = f.Read(b, 0, b.Length)) >0)
* * * * * * * * *{
* * * * * * * * * * *md5.TransformBlock(b, 0, n, garbage, 0);
* * * * * * * * *}
* * * * * * * * *md5.TransformFinalBlock(b, 0, 0);
* * * * * * * * *return BitConverter.ToString(md5.Hash)..Replace("-", "");
* * * * * * *}
* * * * *}
<snip>

Any reason for explicitly doing all the stream reading, rather than
letting ComputeHash do it all for you?

Jon
Jul 14 '08 #7
Maybe this helps::

public static string GetMD5Hash(string filename)
{
MD5CryptoServiceProvider md5 = new
MD5CryptoServiceProvider();
FileStream stream = new FileStream(filename,
FileMode.Open, FileAccess.Read);
byte[] bytes = md5.ComputeHash(stream);
return BitConverter.ToString(bytes).Replace("-", "");
}
Jul 14 '08 #8
On Jul 14, 7:51*am, Kuma <kumasa...@hotmail.comwrote:
Maybe this helps::

* * public static string GetMD5Hash(string filename)
* * * * {
* * * * * * *MD5CryptoServiceProvider md5 = new
MD5CryptoServiceProvider();
* * * * * * *FileStream stream = new FileStream(filename,
FileMode.Open, FileAccess.Read);
* * * * * * *byte[] bytes = md5.ComputeHash(stream);
* * * * * * *return BitConverter.ToString(bytes).Replace("-", "");
* * * * }
One slight modification - I'd always put the stream in a "using"
statement so it gets closed at the end. But yes, that kind of thing :)

Jon
Jul 14 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6880
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
5
1877
by: Francis Bell | last post by:
I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have: string readInFirstChars(ifstream &fin) { char first; string print; while...
8
9986
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
0
2205
by: Si | last post by:
I'm writing an HttpModule to intecept web method calls and retrieve custom authentication information from their SOAP headers. I have the httpModules tag in web.config and that appears to be...
3
3670
by: dei3cmix | last post by:
Hey, I am having a problem with a program I am working on. Basically, the first part of the program gets input from a file using cin.getline. Then the second part, (still in the same main as the...
32
4960
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
2
4202
by: MSK | last post by:
Hi, Continued to my earlier post regaring "Breakpoints are not getting hit" , I have comeup with more input this time.. Kindly give me some idea. I am a newbie to .NET, recently I installed...
4
4457
by: R.Manikandan | last post by:
Hi In my code, one string variable is subjected to contain more amount of characters. If it cross certain limit, the string content in the varabile is automatically getting truncated and i am...
4
5680
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
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,...
0
7175
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
5430
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,...
1
4864
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...
0
3069
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
0
262
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...

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.