471,610 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

MD5 Hashing a file for download checks

I've nearly finished my personal auto updater and the only thing left to
implement is a hash check against the downloaded file to make sure it's
good before extracting it. Right now I havn't released it so I've
tested that the selected update components download correctly and
extract and that the program starts back up as the new version...

I've googled for about a half hour and couldn't figure out how to
generate an MD5 hash for both storing in my website's database and for
generating on the downloaded file to compare against the xml file I
download in the first place in order to download the updates.

So, does anyone have a quick tutorial on how to generate an MD5 hash on
a file?

Thanks in advance,
Benny
Dec 12 '05 #1
4 2569
Hi Benny

Here is a link:
http://msdn2.microsoft.com/en-us/lib...raphy.md5.aspx

Please check the section 'example' - approx. in the middle of the page
given above.
First you have to fill your file into a string - by a text reader

Hope this helps
Roland

Dec 12 '05 #2
is this what i should be doing?

public class MD5Check
{
private string _hash;
private string _file;
public MD5Check(string file, string hash)
{
_hash = hash;
_file = file;
}

public bool Verify()
{
MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
if (File.Exists(_file))
{
FileStream fs = File.OpenRead(_file);
byte[] fileHash = csp.ComputeHash(fs);
fs.Close();

// convert to string
string computed = BitConverter.ToString(fileHash);
if (computed == _hash)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
Dec 12 '05 #3
Benny,

Have you checked out the MD5CryptoServiceProvider class? It takes a
byte array and hashes the contents.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:uq**************@TK2MSFTNGP15.phx.gbl...
I've nearly finished my personal auto updater and the only thing left to
implement is a hash check against the downloaded file to make sure it's
good before extracting it. Right now I havn't released it so I've tested
that the selected update components download correctly and extract and
that the program starts back up as the new version...

I've googled for about a half hour and couldn't figure out how to generate
an MD5 hash for both storing in my website's database and for generating
on the downloaded file to compare against the xml file I download in the
first place in order to download the updates.

So, does anyone have a quick tutorial on how to generate an MD5 hash on a
file?

Thanks in advance,
Benny

Dec 12 '05 #4
Hi,
check this:
.....
using System.Security.Cryptography;

.....

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read,
FileShare.Read);
byte [] HashCode = new MD5CryptoServiceProvider().ComputeHash(fs);
fs.Close();
....

at this point HashCode byte array has the code. Once u receive the file,
perform this operations again and check against the has bits generated for
the received file.

Ab.
http://joehacker.blogspot.com

"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:uq**************@TK2MSFTNGP15.phx.gbl...
I've nearly finished my personal auto updater and the only thing left to
implement is a hash check against the downloaded file to make sure it's
good before extracting it. Right now I havn't released it so I've
tested that the selected update components download correctly and
extract and that the program starts back up as the new version...

I've googled for about a half hour and couldn't figure out how to
generate an MD5 hash for both storing in my website's database and for
generating on the downloaded file to compare against the xml file I
download in the first place in order to download the updates.

So, does anyone have a quick tutorial on how to generate an MD5 hash on
a file?

Thanks in advance,
Benny

Dec 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Dino M. Buljubasic | last post: by
4 posts views Thread by Kevin Blount | last post: by
1 post views Thread by ^MisterJingo^ | last post: by
8 posts views Thread by rdemyan via AccessMonster.com | last post: by
rpnew
9 posts views Thread by rpnew | last post: by
11 posts views Thread by January Weiner | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.