(i’m just trying to find what am I missing…)
Assuming John have a clear text message , he can create a regular hash ( like md5 , or sha256) and then encrypt the message.
John can now send Paul the message + its (clear text)hash and Paul can know if the message was altered. ( decrypt and then compare hashes).
Even if an attacker can change the encrpyted data ( without decrypt) – – when paul will open the message – and recalc the hash – it wont generate the same hash as the one john sent him.
so why do we need hash by key ?


It looks like you don’t have to it is just a good idea to because by including the key in the hash it shows that the data was indeed encrypted with the original key – almost indefinitely. Obviously your example above would work, but I would say you can’t be 100% certain that the message wasn’t intelligently manipulated, or brute force trial-and-errored, to produce a decrypt on the other side that appears correct but doesn’t trigger a hash check failure.
FIPS PUB 198
FEDERAL INFORMATION PROCESSING STANDARDS PUBLICATION
“The Keyed-Hash Message Authentication Code (HMAC)”
Using the above method means you have an extra check for safety. After you decrypt the message you then append the original key to the message and run your hashing function. You then compare the new hash with the one sent. This is a better check because you know that the attacker would have to know the key (or be extremely lucky) in order to generate something that passed the hash check. It’s basically an attempt to try and avoid those attackers that might know hashing functions very well, and limit what alterations they can make.