3.2. Digital Signatures#

Digital signatures are a way to ensure authenticity in digital communications. Just like a handwritten signature verifies the authenticity of a physical document, a digital signature proves that a message or file was created by a specific sender.

Digital signatures rely on asymmetric encryption, with the private key used to sign a message, and the public key is used to verify the signature.

3.2.1. Signing#

To create a digital signature, the sender:

  1. Hashes the message, using a cryptographic hash function e.g. SHA-256

  2. Encrypts the hash, using the sender’s private key to create the signature.

../../_images/digital_signatures_1.png

The sender then sends both:

  1. The original message

  2. The signature.

../../_images/digital_signatures_2.png

3.2.2. Verifying#

To verify a digital signature, the receiver:

  1. Hashes the message, using the same hash function as the sender.

  2. Decrypts the signature, using the sender’s public key into the decrypted hash.

  3. Compares the hash of the message with the hash from the signature.

../../_images/digital_signatures_3.png

If the two hashes match then the signature is valid and it is confirmed that the sender was the creator of the message.

Otherwise the signature is invalid and we cannot confirm that the sender was the creator of the message.

3.2.3. Why Sign the Hash?#

Signing the hash is required because asymmetric encryption can only be applied to as many bits as used for the key. For example if using RSA with a 256 bit key we can only encrypt 256 bits of data. This means that we cannot sign arbitrarily long data.

To get around this, we sign the hash, which uniquely identifies the data regardless of how many bits it occupies.

Signing the hash also provides benefits:

Efficiency

Compared with signing the entire contents of a message:

  • it is much faster to encrypt a relatively short hash

  • it reduces the amount of data that needs to be transmitted over a network

Integrity

Since any change in the message changes the hash it means that we can also verify the integrity of the message. In other words it also confirms that the message was not corrupted or tampered with.