For instance, I do an MD5 of “hashable” using:
protected string hexHashMD5(byte[] filePart) {
// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(filePart);
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.Length; i++) {
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
and store it’s output into a string variable in my program. How can I take that Hash and add another byte[] to create a new hash?
I’ve been told that you can use file stream, to automatically stream in a bit at a time, and make the full hash, but what happens when I need to hash two separate files together?
You can make a custom
Streamclass that reads the two streams in order, then pass that toComputeHash.Alternatively, you can read both streams one block at a time and pass each block to
TransformBlock: