0

HashAlgorithm.TransformFinalBlock is used as the final step to generate a hash. It returns a byte array which is documented as follows:

An array that is a copy of the part of the input that is hashed.

Note that the return value of this method is not the hash value, but only a copy of the hashed part of the input data. To retrieve the final hashed value after calling the TransformFinalBlock method, get the byte array contained in the Hash property.

I'd like to understand what this return value is good for and why the API was designed this way.

Community
  • 1
  • 1
boot4life
  • 4,966
  • 7
  • 25
  • 47
  • 1
    I suppose a design that doesn't fit that well: .NET uses `ICryptoTransform` for encryption and hashing. The interface description for `TransformFinalBlock` is: _...The return value is an array containing the remaining transformed bytes..._ As useful as this is for encryption, it makes less sense for hashing. So `TransformFinalBlock` returns what comes closest to the interface description, which in case of hashing are the remaining bytes. A definitive answer can probably only be given by the MS architects. – Topaco Jun 09 '20 at 13:17
  • The return value seems useless to me. The documentation is terrible, contradictory in fact. Welcome to .Net. – President James K. Polk Jun 09 '20 at 14:08

0 Answers0