473,769 Members | 5,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2712
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()
{
MD5CryptoServic eProvider csp = new MD5CryptoServic eProvider();
if (File.Exists(_f ile))
{
FileStream fs = File.OpenRead(_ file);
byte[] fileHash = csp.ComputeHash (fs);
fs.Close();

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

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

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

"Benny Raymond" <be***@pocketro cks.com> wrote in message
news:uq******** ******@TK2MSFTN GP15.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(file name, FileMode.Open, FileAccess.Read ,
FileShare.Read) ;
byte [] HashCode = new MD5CryptoServic eProvider().Com puteHash(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***@pocketro cks.com> wrote in message
news:uq******** ******@TK2MSFTN GP15.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
5400
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 completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
10
2868
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 introduce some characters in my password that are not handled properly by SQL server then. For example, password 'startreck' works just fine password 'test' does not
4
1650
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 and passwords and an email to us with 'who did what and when' info. a typical link from this system might be http://www.oursite.com/getfile.asp?id=123 My current task is to allows link directly to the file (for a cleaner
1
395
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 page checks for this before allowing access). To stop files being downloaded through a link to them on a server (potentially allowing unauthorized people access) I've put the directory containing the files outside of the web root. This all works...
2
23901
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 completed the download or cancelled out before it completed. Is there any function in PHP that would allow the web server to send the file and detect a completion or cancellation? Or perpahs a javascript/PHP method? Any help would be greatly...
8
1937
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 current date/time when the back-end file is compacted. I'm just looking for an easy way to determine when there has been a change to data in any table in the back-end file. Maybe something is updated in one of the system tables??
9
2288
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 using one code (got from internet) i tried to modified it every way but every time file download dialog box opens but it downloads blank file.. neither it checks for file existence..... any help would be appreciated.. Presently i'm using...
11
2158
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 values in two dimensional matrices each time that I encounter a pair of these strings. I would like to keep the code as simple and standard as possible, but at the same time to have a reasonable performance.
1
47483
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9579
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
9416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
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...
1
9979
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9849
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8861
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
7393
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
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
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

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.