How is a message digest decrypted? Trying to get my head around digital signatures and hit a slight block. The book I am using gives the following information


Device A hashes a message to create a message digest 
Device A encrypts the digest with device A's private key to create a signature    
Device A adds the signature to the message Device A encrypts the whole message (including the signature) using device B's public key      
Device A sends the message to device B

Device B decrypts the message with device B's private key
Device B splits the signature off of the message
Device B decrypts the signature using device A's public key to get the message digest
Device B hashes the message to get a message digest
If the message digest device B created is the same as the one decrpyted, the message has not been tampered with


All fine, but how does device B know what hashing algorithm was used to create the message digest?
First of all signing does not equal encrypting. It only works on some crypto systems and even then it is not the whole picture. 

Hash algorithms are used for various reasons. One of them is to reduce the size of the signature since the digest is generally a lot smaller than the message itself.

But the main cryptographic reason behind hash functions is to make it so that a possible attacker cannot force the message he wants to forge a signature for, to have a certain property.

It is a bit technical but for example in the ElGamal cryptosystem if you sign the message itself then it is possible for an attacker to produce a valid signature without knowing the secret key. If however you sign the hash of the message  then this is not possible.