Message Digest is used to ensure the integrity of a message transmitted over an insecure channel (where the content of the message can be changed). It refers to a fixed-size numerical representation (hash value) of a message or data, created by a hash function.
It's a core concept in ensuring data integrity. The message is passed through a Cryptographic hash function. This function creates a compressed image of the message called Digest.
Message Digests Characteristics
Purpose: To verify that data has not been altered.
Security Use: Common in digital signatures, data integrity checks, and password storage.
Generated By: Cryptographic hash functions like MD5, SHA-1, SHA-256.
Fixed Output: No matter the size of the input data, the output (digest) is of fixed length.
Non-reversible: You cannot retrieve the original data from its message digest (one-way function).
Deterministic: The same input will always produce the same output.
Collision-resistant: It should be hard to find two different inputs that produce the same digest.
Working of Message Digest
Lets assume, Alice sent a message and digest pair to Bob.
This message and digest pair is equivalent to a physical document and fingerprint of a person on that document. Unlike the physical document and the fingerprint, the message and the digest can be sent separately.
Sender Side (Creating the Digital Signature)
Compose the Message The sender writes or generates the message they want to send.
Generate the Message Digest The sender uses a cryptographic hash function (e.g., SHA-256) to create a message digest (fixed-length hash) from the original message.
Example: Digest = Hash(message)
Encrypt the Digest with Private Key The sender encrypts the digest using their private key.
This encrypted digest is now the digital signature.