I tried to follow this advice, but I still run out of memory.
http://bytes.com/topic/visual-basic-net/answers/363011-md5-large-files
Basically, I am reading all the bytes of a 1 gb disk and I want to try and do a md5 hash on it. However, when following this example, my cryptostream gets too large a System out of memory exception.
Is there another way to do the md5 hash over some much data?
I am currently reading it into 10 million bytes arrays at a time. Can I hash the first array, and then use it as a seed for the next array, and so one, like you might do to a CRC32 calculation?
Any help would be appreciated.
2 2904
Can you post your code?
You won't be able to feed the result of one hash into another because of the preprocessing that is done for MD5 hashes. However, you can do the hash append yourself. You will not get an officially correct MD5 hash but as long as you hash using the same function, the essence is the same.
Also, I found this on google. - Imports System.Security.Cryptography
-
Imports System.Text
-
Imports System.IO
-
-
Module RijndaelSample
-
-
Sub Main()
-
Try
-
' Create a new Rijndael object to generate a key
-
' and initialization vector (IV).
-
Dim RijndaelAlg As Rijndael = Rijndael.Create
-
-
' Create a string to encrypt.
-
Dim sData As String = "Here is some data to encrypt."
-
Dim FileName As String = "CText.txt"
-
-
' Encrypt text to a file using the file name, key, and IV.
-
EncryptTextToFile(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV)
-
-
' Decrypt the text from a file using the file name, key, and IV.
-
Dim Final As String = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV)
-
-
' Display the decrypted string to the console.
-
Console.WriteLine(Final)
-
Catch e As Exception
-
Console.WriteLine(e.Message)
-
End Try
-
-
Console.ReadLine()
-
-
End Sub
-
-
-
Sub EncryptTextToFile(ByVal Data As String, ByVal FileName As String, ByVal Key() As Byte, ByVal IV() As Byte)
-
Try
-
' Create or open the specified file.
-
Dim fStream As FileStream = File.Open(FileName, FileMode.OpenOrCreate)
-
-
' Create a new Rijndael object.
-
Dim RijndaelAlg As Rijndael = Rijndael.Create
-
-
' Create a CryptoStream using the FileStream
-
' and the passed key and initialization vector (IV).
-
Dim cStream As New CryptoStream(fStream, _
-
RijndaelAlg.CreateEncryptor(Key, IV), _
-
CryptoStreamMode.Write)
-
-
' Create a StreamWriter using the CryptoStream.
-
Dim sWriter As New StreamWriter(cStream)
-
-
Try
-
-
' Write the data to the stream
-
' to encrypt it.
-
sWriter.WriteLine(Data)
-
Catch e As Exception
-
-
Console.WriteLine("An error occurred: {0}", e.Message)
-
-
Finally
-
-
' Close the streams and
-
' close the file.
-
sWriter.Close()
-
cStream.Close()
-
fStream.Close()
-
-
End Try
-
Catch e As CryptographicException
-
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message)
-
Catch e As UnauthorizedAccessException
-
Console.WriteLine("A file error occurred: {0}", e.Message)
-
End Try
-
End Sub
-
-
-
Function DecryptTextFromFile(ByVal FileName As String, ByVal Key() As Byte, ByVal IV() As Byte) As String
-
Try
-
' Create or open the specified file.
-
Dim fStream As FileStream = File.Open(FileName, FileMode.OpenOrCreate)
-
-
' Create a new Rijndael object.
-
Dim RijndaelAlg As Rijndael = Rijndael.Create
-
-
' Create a CryptoStream using the FileStream
-
' and the passed key and initialization vector (IV).
-
Dim cStream As New CryptoStream(fStream, _
-
RijndaelAlg.CreateDecryptor(Key, IV), _
-
CryptoStreamMode.Read)
-
-
' Create a StreamReader using the CryptoStream.
-
Dim sReader As New StreamReader(cStream)
-
-
' Read the data from the stream
-
' to decrypt it.
-
Dim val As String = Nothing
-
-
Try
-
-
val = sReader.ReadLine()
-
-
Catch e As Exception
-
Console.WriteLine("An Cerror occurred: {0}", e.Message)
-
Finally
-
' Close the streams and
-
' close the file.
-
sReader.Close()
-
cStream.Close()
-
fStream.Close()
-
-
-
End Try
-
-
' Return the string.
-
Return val
-
-
Catch e As CryptographicException
-
Console.WriteLine("A Cryptographic error occurred: {0}", e.Message)
-
Return Nothing
-
Catch e As UnauthorizedAccessException
-
Console.WriteLine("A file error occurred: {0}", e.Message)
-
Return Nothing
-
End Try
-
End Function
-
End Module
If push comes to shove and nothing else works, and you must have an official MD5 hash, you can implement the algorithm yourself.
Thanks for your reply, but I think I found a better way of doing it. This is what I did if anyone is interested based on msdn.
This snippet assume 10 total large blocks of date to hash together. Readsize is number of elements in array, i.e. the length.
Using the following as a basis, I was able to computer a md5 hash over 1gb of data.
Dim md5Hash As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
dim arrRead() as byte
dim arrHash() as byte
for i = 1 to 9
arrRead = ReadDataIntoDataBlock(i)
md5Hash.TransformBlock(arrRead, 0, ReadSize, arrRead, 0)
next i
'For the last, in this case, 10th block use
'TransformFinalBlock.
arrRead = ReadDataIntoDataBlock(10)
arrRead = md5Hash.TransformFinalBlock(arrRead, 0, ReadSize)
arrHash = md5Hash.Hash
'arrHash now contains 16 byte hash
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ice Man |
last post by:
Hi All,
I will need to send bewteen 2 asp pages very large amounts of data
what is the best way to send it and to read it?
for ex. I know this method:
For i = 1 To Request.QueryString.Count...
|
by: steve |
last post by:
Hi, I have researched but have not found a good solution to this
problem.
I am importing large amounts of data (over 50 Meg) into a new mysql db
that I set up. I use
>mysql dbname <...
|
by: Mike |
last post by:
This is a general question on the best way to import a large amount of data
to a MS-SQL DB.
I can have the data in just about any format I need to, I just don't know
how to import the data. I...
|
by: Bart |
last post by:
Dear all,
I would like to encrypt a large amount of data by using public/private keys,
but I read on MSDN:
"Symmetric encryption is performed on streams and is therefore useful to
encrypt large...
|
by: loretta |
last post by:
I have data within an xml tag that is being truncated when being read
into a javascript variable. On Firefox, I am only getting up to 4096
characters. On IE, I am getting 31324 characters. I can...
|
by: eggie5 |
last post by:
OK, so I'm trying to get a large amount of text back to my ASP script
on the server. My large amount of text is the source to a web page, and
I want to preserve the formatting on it, ie the...
|
by: Pja |
last post by:
hi..
i need some help here..
how do i display large amount of data in vb6.0 in a table form that can be scrolled and to include print functions..
i am using vb6.0 as my front end and ms sql server...
|
by: Jack |
last post by:
I need to process large amount of data. The data structure fits well
in a dictionary but the amount is large - close to or more than the size
of physical memory. I wonder what will happen if I try...
|
by: AnishAbs |
last post by:
Hi ,
I have got a senario in which large amount of data should be copied from MS excel to MS SQL server. which is the best option to do so. Because when I use recordsets the process is very slow and...
|
by: Ale |
last post by:
Hi all,
how can I execute a large amount of DDL Queries on Access 2000?
I've a DDl/SQL Script file which defines a data structure with CREATE
TABLE, ALTER TABLE UPDATE TABLE, etc. etc.
I know...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
| |