473,395 Members | 1,653 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,395 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 2683
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
10
by: Dino M. Buljubasic | last post by:
Hi, I am using MD5 to hash my passwords and add them to database as hashed. I have noticed though that some passwords don't get recognized and I suppose that it happen because hashing might...
4
by: Kevin Blount | last post by:
My current site uses a ASP, database driven, ID based system to allow people to download files they have the right permissions to, as well as to send an email to them with necessary support links...
1
by: ^MisterJingo^ | last post by:
Hi all, I've written some code which allows a user to browse a directory and any subdirectories it contains. The page which contains this can only be browsed by users with a certain cookie (the...
2
by: Dan D | last post by:
I have a large install file (an exe) on my web server that people download and install from. Looking at my log files, I see a lot of people downloading it, but no way to tell for sure if they...
8
by: rdemyan via AccessMonster.com | last post by:
Anyone have any ideas on how to determine when the back-end file (containing only tables) has been updated with new data. The date/time of the file won't work because it gets updated to the...
9
rpnew
by: rpnew | last post by:
Hi, I'm very new to PHP and making one project.. what i want to do is .. i want to make a file download facilities thorough which user of my web pages can download selected file. presently i'm...
11
by: January Weiner | last post by:
Hello, I need to use a hashing function for relatively short strings (roughly 16 characters or less). The data that needs to be accessed via hash is just a simple int. I just need to look up...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.