Breaking down Encryption and Hashing in Blockchain Technology
By: Yogesh Niroula
Tags: Encryption, Cryptography, Bitcoin, Cryptocurrency, Mining

1. Symmetric key encryption

In symmetric key encryption, the same key is used for encryption and decryption. Caesar encryption is a type of symmetric key encryption where each letter is shifted to fixed positions.

For example: If Ram wants to send a message, “HOW ARE YOU” to Shyam using Caesar encryption, Ram would move the letters certain position left or right and send it to Shyam. Here in this example, we will shift 3 letters right from each letter's position and now the message reads, “KRZ DUH BRX”. The message with sifted letters will be sent to Shyam. Since Shyam already knows the rules of this encryption he would easily decrypt the message by positioning 3 letters left and read the message.

2. Public Key OR Asymmetric Cryptography

Public key cryptography is used to authenticate, validate and create trust between transactions involving several users in a decentralized network. It is done by using a public key cryptography algorithm. Unlike symmetric key encryption which produces a single secret key, asymmetric cryptography produces two secret keys that are mathematically related but are not identical. Those are:

• Public Key: Is used to encrypt.

• Private Key: Is used to decrypt.

PUBLIC KEY can be freely shared for validation purposes. It is computationally not possible to find the PRIVATE KEY based on the PUBLIC KEY. PRIVATE KEYS are stored privately and only the owners of the private keys can decrypt the content that is sent using the public key.

Below are a few popular public key encryption techniques that is currently being used widely in the market:

RSA Algorithm:

(i) Passwordless user authentication.

(ii) SSL Certificates used by web browsers.

(i) Passwordless user authentication. (ii) SSL Certificates used by web browsers. Elliptic Curve Cryptography(ECC):

(i) Used by Bitcoin and Ethereum for generating the key pair.

3. Hashing

Hash/Hashing creates any type or size of message, dataset or block value to a unique and fixed length hash signature using a hash function. If the value has a slight change in any message, data or block, a different hash function is produced. Most common hash size now is 256-bits length hash and most commonly used hash functions in blockchains are MD 5, SHA-3, SHA-256(currently used by Bitcoin) and Keccak-256(currently used by Ethereum). The hash is so unique that in order to figure out the size of 256-bits length hash we have to guess 2²⁵⁶ possible combinations.

The quality of hashing is that every hash is unique and a hash cannot be decrypted like symmetric and asymmetric key encryption.

Fig: Hashing algorithm

Two approaches of hashing techniques:

Simple hashing:

All the data items are linearly approached and hashed.

All the data items are linearly approached and hashed. Merkle tree hashing:

All the data items are at the leaf nodes of the tree and leaves are combined in a pair and hashed again as a simple hashing approach. Merkle tree allows for the detection of any changes of any data within the transaction of a block by simply rerunning the hash through the transaction and comparing the hash with the original root hash. It is an important part of blockchain for data integrity.

In the figure above: There are 4 transactions and those each transaction contain data. Each transaction is passed through the hash function which generates a unique hash. 4 hashes are now combined with 2 and passed through hash function again which creates a unique hash. Again, the last 2 hashes are combined which results in a single root hash making a complete Merkle Tree. Merkle tree allows for the detection of any data within the transactions of a block by rerunning the transactions and comparing to the original root hash.