Cryptography fundamentals, part three - Hashing

Security Ninja
March 5, 2015 by
Security Ninja


A hash value, also called a message digest, is a number generated from a string of text. As per the hash definition, no two different texts should produce the same hash value. If an algorithm can produce the same hash for a different string of text, then that algorithm is not collision free and can be cracked. Various examples of hash algorithm are like MD2, MD5 and SHA-1 etc.

Here's how to create a hash of a file, and how to detect whether the hash changes when changing the document.

Learn Applied Cryptography

Learn Applied Cryptography

Build your applied cryptography and cryptanalysis skills with 13 courses covering hashing, PKI, SSL/TLS, full disk encryption and more.

[download]Download the Cryptography Fundamentals eBook (FREE)[/download]

Demonstration of Hashing using CrypTool

  1. Click on "Indiv Procedures" > Hash>Hash Demonstration.
  2. The message below will appear.

  3. We have selected the SHA-160 algorithm to generate a hash.
  4. Since there is no change in text, both the original and modified values are the same. Let's change the text in the file.

I added the word "modified" to the original document.

The hash values are different because the original and final documents are different.

Generation of HMAC using CrypTool

Only one type of hash is possible for a specific text (provided there's no collision), which means the file has integrity. But an attacker could modify the file, recalculate the hash of the modified file, and replace the old hash with the modified one.

That problem is solved using Hash Message Authentication Code (HMAC), which uses a secret key to calculate the hash. That key is secret between the entities. Unless the attacker has the key, they're unable to calculate a valid hash value of the modified data. To generate a HMAC in CrypTool, perform the following steps:

  1. Click on "Indiv Procedures" >Hash > Generation of HMACs .
  2. Select the SHA-1 160 bit hash, and leave the key empty.
  3. Because we haven't selected a key, this message will appear.

  4. The message shows that the difference between a simple hash and HMAC are the keys.
  5. Below is the hash, or the HMAC value in this case.

Enter key value "Infosec Institute" and see the difference in the generated HMAC. In this case I have chosen the HMAC to be in front of the message.

Digital signatures

A digital signature added to a document shows the sender's identity. It can also provide non-repudiation. The sender cannot deny sending the document, only the sender has that digital signature. Digital signatures are created through multiple steps. We need to understand all the steps that must be performed before a digital signature can be generated.

Demonstration of digital signatures using CrypTool

Digital Signature Creation

  1. First we need to generate a hash value of the document. To generate it, we need to select a hashing algorithm. We'll use the MD5 algorithm.
  2. Next, generate a key pair. We'll generate RSA keys. For RSA key generation, two large prime numbers and a mathematical function are required.
  3.  After successfully generating keys, encrypt the hash value generated earlier.
  4. We need to create a certificate associated with the RSA key. Provide the following details and click on "create certificate." It'll be used for communication between the sender and recipient.030415_2200_Cryptograoh10.pngClick on generate signature to create a digital signature.
  5. 030415_2200_Cryptograoh11.pngClick on "store signature."



Signing with digital signature

Select the document to apply the signature. We'll select our Infosec document.

  1. Click on "Digital Signature" > Sign.
  2. Select the digital signature we just created. Enter the PIN code from the signature creation process, and click on sign.
  3. Verifying the digital signature

    1. Click on "Digital Signatures" > Verify signature.
    2. Select the Digital Signature created above
    3. 030415_2200_Cryptograoh15.pngThis message confirms a correct signature.

    The difference between HMAC and digital signatures

    The difference is the type of key being employed. In HMAC, the key that is used is symmetric, and digital signatures uses an asymmetric key.

    Learn Applied Cryptography

    Learn Applied Cryptography

    Build your applied cryptography and cryptanalysis skills with 13 courses covering hashing, PKI, SSL/TLS, full disk encryption and more.


    Security Ninja
    Security Ninja