By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,581 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,581 IT Pros & Developers. It's quick & easy.

MD5 Hashing a file for download checks

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.