Lets say I’m doing something like:
FileStream fs = File.OpenRead("xxx.xxx");
byte[] buffer = new byte[1024];
int count;
long pos = 0, length = fs.Length;
MD5 md5 = MD5.Create();
while(pos < length && (count = fs.Read(buffer, 0, 1024)) > 0)
{
doWork(buffer, count);
md5.AddBlock(buffer, count); // <- Is this possible?
}
byte[] checksum = md5.GetChecksum(); // <- Possible?
I would like to be able to calculate the MD5 Checksum as I’m going through the stream… is this possible?
The two methods you are looking for are TransformBlock and TransformFinalBlock. They will do exactly what you are looking for.