Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate hash without having the entire buffer in memory at once

Tags:

c#

.net

hash

md5

I am doing an operation where I receive some bytes from a component, do some processing, and then send it on to the next component. I need to be able to calculate the hash of all the data I have seen at any given time - and because of data size; I cannot keep it all in a local buffer.

How would you calculate the (MD5) hash under these circumstances ?

I am thinking that I should be able to hold on to an intermediate result of the hash, and add more data as I go. But does any of the built-in framework classes support this ?

like image 344
driis Avatar asked Aug 26 '09 09:08

driis


1 Answers

You simply want to use the TransformBlock and TransformFinalBlock members of the class, which allow you to compute the hash in chunks.

MSDN has a good example of how to do this.

like image 59
Noldorin Avatar answered Sep 28 '22 05:09

Noldorin