Yes, it's fine to pass null
. The reason it even has this parameter is because it's implementing the ICryptoTransform
interface. This interface can be used when constructing CryptoStream
s because you might want to build up a set of transformations. In this case, HashAlgorithm
doesn't change the data at all so it ends up funnily defined as just copying the input to the output.
Other implementations of ICryptoTransform
(e.g. anything that actually performs encryption or decryption) would of course also be writing non-trivial output.
This means that, during a single pass over an input, you can compute the hash while also performing encryption - that's why this interface is supported here.
The current implementation just has this, after it's done its work:
if ((outputBuffer != null) && ((inputBuffer != outputBuffer) ||
(inputOffset != outputOffset)))
Buffer.BlockCopy(inputBuffer, inputOffset,
outputBuffer, outputOffset, inputCount);