473,785 Members | 2,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MD5 hash on very large files 500mb to 4gb+

I need to compute the MD5 hash on VERY large files 500mb to 4gb+

I have found two ways but neither one of them does what i need.

Private Function ComputeDataMD5( ByVal path As String) As String
Dim fi As New FileInfo(path)
Dim fs As FileStream = fi.OpenRead()
fs = fi.OpenRead

Dim Md5 As New MD5CryptoServic eProvider
Dim hash As String =
BitConverter.To String(Md5.Comp uteHash(fs)).Re place("-", "")

'fs.Close()
ComputeDataMD5 = hash.ToLower
End Function

This function uses the filestream object to create the hash from,
problem is that it locks up the application and does not allowe me to
show/update a progress bar.
Function GetHash(ByVal path As String) As String

Dim cs As CryptoStream
Dim ms As MemoryStream = New MemoryStream
Dim md5Hash As MD5CryptoServic eProvider = New
MD5CryptoServic eProvider

Dim fi As New FileInfo(path)
Dim fs As FileStream = fi.OpenRead()

Try

fs = fi.OpenRead

Dim buffer(1024) As Byte
Dim size As Integer

Do While fs.Position <> fs.Length
size = fs.Read(buffer, 0, 1024)

cs = New CryptoStream(ms , md5Hash,
CryptoStreamMod e.Write)
cs.Write(buffer , 0, size)
Loop

cs.FlushFinalBl ock()
Return BitConverter.To String(md5Hash. Hash()).Replace ("-",
"").ToLower
Catch ex As Exception

MsgBox("Error during hash operation: " + ex.ToString())

Finally
If Not (fs Is Nothing) Then fs.Close()
If Not (cs Is Nothing) Then cs.Close()
If Not (md5Hash Is Nothing) Then md5Hash.Clear()
End Try
End Function

This function reads a block of data and places it into the
CryptoStream object, after we are done reading the file we compute the
MD5. Problem with this function is that it reads the whole file into
memory, 500mb file = 500mb in ram.
Since i need to compute hash on files that are in the range of 4gb
this method is useless.
Nov 21 '05 #1
3 6470
This function uses the filestream object to create the hash from,
problem is that it locks up the application and does not allowe me to
show/update a progress bar.


generate the hash on another thread so that the main thread is free to
update the form and its controls and wont lock up.
Imran.
Nov 21 '05 #2
This function uses the filestream object to create the hash from,
problem is that it locks up the application and does not allowe me to
show/update a progress bar.


generate the hash on another thread so that the main thread is free to
update the form and its controls and wont lock up.
Imran.
Nov 21 '05 #3

As Imran said, put it in a separate thread to leave the main thread
open to update the UI.

As for generating a progress bar, you'll need to get the progress of
the Hash. To do this you can create a custom stream that wraps
FileStream and broadcasts progress events. Or you can use an
indeterminate progress bar that just shows something is hapenning
without showing the percent completed.

HTH,

Sam

On 22 Sep 2004 15:01:25 -0700, ps*********@ins ightvideonet.co m (Paul
Spielvogel) wrote:
I need to compute the MD5 hash on VERY large files 500mb to 4gb+

I have found two ways but neither one of them does what i need.

Private Function ComputeDataMD5( ByVal path As String) As String
Dim fi As New FileInfo(path)
Dim fs As FileStream = fi.OpenRead()
fs = fi.OpenRead

Dim Md5 As New MD5CryptoServic eProvider
Dim hash As String =
BitConverter.T oString(Md5.Com puteHash(fs)).R eplace("-", "")

'fs.Close()
ComputeDataMD5 = hash.ToLower
End Function

This function uses the filestream object to create the hash from,
problem is that it locks up the application and does not allowe me to
show/update a progress bar.

Nov 21 '05 #4

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

Similar topics

6
6165
by: shailesh kumar | last post by:
Hi, I need to design data interfaces for accessing files of very large sizes efficiently. The data will be accessed in chunks of fixed size ... My data interface should be able to do a random seek in the file, as well as sequential access block by block.... One aspect of the usage of this interface is that there is quite good chance of accessing same blocks again and again by the application..
5
7208
by: Michael H | last post by:
Hi all, I guess I don't fully understand how a SHA1 hash value is calculated in C# / .NET for a large file... I'm trying to calculate SHA1 values for large files that are much larger than my physical main memory. It seems the way to derive a SHA1 value involves opening a file stream to the large file, passing it to a byte array, and passing the byte array to the .NET hash method. Does this load the entire file into main memory (within...
4
2401
by: Sebastian Dau | last post by:
Hello, I'm writing a security related application in .NET 1.1 and I wonder how I compute hashes from very large files (up to 1 GB). Does anybody know a good pattern of how to create a stream from a binary file and compute the hash of it?
0
1583
by: ajayguptab | last post by:
Hi Friends, I need to copy large files (more than 500mb) from one node to another node. ( node has some hard disks ). or let me know how to compress a huge file into a small file((then i can send it) and decompress it.
1
6321
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the...
12
1602
by: raj | last post by:
Hi friends, In an interview I was asked to write a C program to create a large file of 8GB The first 4GB is filled with "Hello" and the secod 4GB is filled with "World" Sorry to say that I don't know how to do that in an elegant way. I think
2
3199
by: robert | last post by:
Somebody who uses my app gets a error : os.stat('/path/filename') OSError: Value too large for defined data type: '/path/filename' on a big file >4GB ( Python 2.4.4 / Linux )
17
9953
by: byte8bits | last post by:
How does C++ safely open and read very large files? For example, say I have 1GB of physical memory and I open a 4GB file and attempt to read it like so: #include <iostream> #include <fstream> #include <string> using namespace std; int main () {
6
7483
by: Terry Carroll | last post by:
I am trying to do something with a very large tarfile from within Python, and am running into memory constraints. The tarfile in question is a 4-gigabyte datafile from freedb.org, http://ftp.freedb.org/pub/freedb/ , and has about 2.5 million members in it. Here's a simple toy program that just goes through and counts the number of members in the tarfile, printing a status message every N records (N=10,000 for the smaller file;...
0
9647
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
9485
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
10356
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
10098
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
9958
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
8986
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...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4058
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
3
2890
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.