tags:

views:

92

answers:

2

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 ?

A: 

Its a bit surprising that it doesn't come in the box.

If you create the MD5CryptoServiceProvider in a member variable, and call ComputeHash() repeatedly, does it not work as an append?

Will
No, ComputeHash repeatedly, does not work. The TransformBlock / TransformFinalBlock approach seems to be working, I am currently testing it out.
driis
+2  A: 

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.

Noldorin
TransformBlock / TransformFinalBlock works; but if the chunks you can pass to the TransformFinalBlock function is not the same size, or larger, than the hash, you need to use the HashAlgorithm.Hash property to get the hash after calling TransformFinalBlock.
driis
Ah, glad it's working for you now.
Noldorin