I am checking the file hashes using several different algorithms in powershell. When I use MacTripleDes, I always get different hashes. All of the others, such as SHA256 or MD5 always give reliable answers. You may be able to replicate the problem on your own computer:
"this is a test" | out-file test.txt
get-filehash test.txt -algorithm sha256
get-filehash test.txt -algorithm sha256
get-filehash test.txt -algorithm mactripledes
get-filehash test.txt -algorithm mactripledes
I get the same hash values for the first two hashes, but differing values for the second two hashes. Is MacTripleDes supposed to be used differently?
Algorithm Hash Path
--------- ---- ----
SHA256 3F8CB2CDF03347329CAB0C80A6CE3B01EF3B17AF02E0F6E101FA67CE63729F51 C:\temp\test.txt
SHA256 3F8CB2CDF03347329CAB0C80A6CE3B01EF3B17AF02E0F6E101FA67CE63729F51 C:\temp\test.txt
MACTRIPLEDES 904D74A529C7A739 C:\temp\test.txt
MACTRIPLEDES AF720778A2C878A2 C:\temp\test.txt
MACTripleDES is different than the other algorithms that are offered by the
Get-FileHash
cmdlet. I'm not sure why it was included in the cmdlet, to be honest. It doesn't fit with the others, IMO.SHA1, SHA256, MD5, RIPEMD, etc., those are all regular hash functions. They take some data of arbitrary length and create a digest of fixed length that represents that data. MACTripleDES is different though, in that it's not just a hash algorithm. It has TripleDES in the name, and 3DES is an encryption algorithm, not a hashing algorithm. The biggest difference between hash functions and encryption functions is that encryption can be reversed with a key. Hashes are one-way functions.
And MAC stands for message authentication code. It's a code that's used to authenticate a message. To verify that it wasn't tampered with. MACs are designed to be ephemeral or unique from one message to the next.
Check out the constructor:
StaticRandomNumberGenerator generates random numbers... random numbers means the result is going to be different each run.