Why isn't MacTripleDes algorithm output in PowerShell stable?
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:
public MACTripleDES() {
KeyValue = new byte[24];
Utils.StaticRandomNumberGenerator.GetBytes(KeyValue);
// Create a TripleDES encryptor
des = TripleDES.Create();
HashSizeValue = des.BlockSize;
m_bytesPerBlock = des.BlockSize/m_bitsPerByte;
// By definition, MAC-CBC-3DES takes an IV=0. C# zero-inits arrays,
// so all we have to do here is define it.
des.IV = new byte[m_bytesPerBlock];
des.Padding = PaddingMode.Zeros;
...
StaticRandomNumberGenerator generates random numbers... random numbers means the result is going to be different each run.