✅ Can't figure out a way to make TransformFinalBlock work
here's my code
how I use it is for a download function that needs to hash the data that is beeing downloaded in small packets, dynamically as the download goes on. I believe that is exactly what TransformBlock and TransformFinalBlock are made for.
The little debug thing works for the 1st method, it does display valus that seem coherents.
But the 2nd method is the issue, TransformFinalBlock returns an empty array, and that sucks. I don't set any paramaters since all of that is done with TransformBlock, and I believe TransformFinalBlock returns the hash resulting from all the blocks given to TransformBlock. So what is the issue here and how can I fix it ?
Thx for any help in advance.
13 Replies
Did you read the documentation for TransformFinalBlock?
yes but I don't understand it
Computes the hash value for the specified region of the specified byte array.But you are passing it nothing to do any work on.
then when I'm using transformBlock, how do I finalise it ?
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 believe you access the
_sha1.Hash property after you call TransformFinalBlock.is there a reason you are not using the IncrementalHash class
(Also, SHA1 is generally out of favor these days.)
because I did not know how hash worked before
using sha1 is necessary for my project, the server gives that king of hash
the server being piston-meta.mojang.com, which is used by launchers to download minecraft
not my choice
so do I even need to use TransformFinalBlock then ?
Sure, that's fine then.
I think you do.
alr thx
You might also look into using the type that @reflectronic suggested:
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.incrementalhash?view=net-9.0
It might be a bit more ergonomic to use. (I've never used it myself though.)
IncrementalHash Class (System.Security.Cryptography)
Provides support for computing a hash or HMAC value incrementally across several segments.
yeah it seems better
how do I mark this post as solved