Why RSA signatures based on the hash of the message rather than the message itself?
2 Answers
The hash acts as a measure to determine if the message has been changed since it was signed. That way the recipient knows that the message is the same as when it was signed (integrity).
Message is composed
Message is hashed
Hash is encrypted with sender's private key
The resulting signature accompanies the message
The recipient can use the sender's public key to check the hash, thereby confirming the integrity of the message and that the sender was the one who signed it (non-repudiation). A digital signature means that the message is as intended and sent by a confirmed source.
Applying the private key to the hash is more computationally efficient (smaller thing to encrypt), and encrypting the message may not be necessary if confidentiality is not required/desired.
Technically, the signature works over the message; it so happens that the first step of the signature generation algorithm is to hash the message with a hash function, and the hash value is used afterwards.
Using a hash function is necessary because the RSA algorithm relies on integers modulo a given integer (which is part of the public key), so it cannot work with values which do not fit in that limited range. The hash function is also needed to ensure non-malleability (a rather technical internal characteristic). Using a hash function is sufficient because of the properties of cryptographic hash functions; namely, the resistance of hash functions to collisions and preimages really means that signing a hash is "as good" as signing the original message.