Hashing, asymmetric encryption, and digital signatures

We discussed the challenges that arise in a decentralized transaction system in the previous article. We shall begin to delve into how blockchain addresses these challenges in this article by learning about hashing, asymmetric encryption, and how we use them to produce digital signatures.

In the wake of the financial crisis in 2008 was launched Bitcoin which offered a solution to the two major concerns in a decentralized currency—reaching consensus and verifying authenticity. Bitcoin in many ways is a digital gold standard. Just like gold, bitcoins are scarce—meaning that you can’t create this currency out of thin air. Bitcoins need to be mined just like how gold should be mined and the rate at which they can be mined is limited. In addition, like gold, Bitcoins are global and aren’t tied to a certain country and act as international base money.

So, how do Bitcoin and the underlying technology—blockchain—help solve the problem of consensus and user authentication?

Before we see how blockchain goes about solving these two problems, there are two major building blocks of blockchain we need to know about. They are hashing and asymmetric encryption. Let’s see what they are and how they work even though we shall see the roles these two play in blockchain later.

Hashing

Hashing converts any data into a fixed-sized string. Think of it like a machine that takes in any data as an input and outputs a string of a fixed size. The output size doesn’t change no matter what. So, the size of the output string remains the same whether you input a two-digit number or the entire text of a novel.

We call this output string a hash. A major advantage of hashing is that in no way can you convert a hash back into the original data. This advantage renders hashing many of its use cases. There are many hashing algorithms available and the one that Bitcoin uses is SHA-256 which produces a string that is 256 bits long.

Asymmetric Encryption

On the other hand, asymmetric encryption is an encryption technique. Unlike the usual symmetric encryption, where we use one key to both encrypt and decrypt data, asymmetric encryption uses a pair of keys known as private and public keys. We can calculate the public key from the private key but not vice-versa.

When we encrypt data using one key, we can decrypt it only with the other key. For instance, we can decrypt the data encrypted using the private key only with the corresponding public key and vice versa. We can share the public key publicly whereas we have to keep the private key private.

Confidentiality

When encrypting data using the public key, then only the private key can decrypt that data. This ensures confidentiality. That is, if Alice wants to send a secret message to Bob, then Alice can use Bob’s public key, which is publicly available, to encrypt the data before sending it to Bob. Once encrypted, we can decrypt the data only by Bob’s private key. Since only Bob has the private key, only Bob can read the data. This way we ensure confidentiality.

Authenticity

Similarly, when we encrypt data using the private key, we can decrypt it only with the public key. This can help us verify the authenticity of data. Suppose Alice wants to send a message to Bob, and Bob wants to confirm that it was indeed Alice who sent the message, then Alice can encrypt the message with her private key before sending it to Bob. If Bob can decrypt the message with Alice’s public key, then Bob can ensure that it was Alice’s private key that was used to encrypt the message. Since only Alice can have the private key, we can confirm the authenticity of the message.

A popular algorithm used to generate the public and private keys is the RSA algorithm but Bitcoin uses the ECDSA algorithm.

Digital Signatures

We use hashing and asymmetric encryption to create digital signatures. Blockchain transactions use digital signatures extensively, and it is not an overstatement to say that blockchain transactions would fall apart without digital signatures.

We create a digital signature by hashing the data and then encrypting it using the private key. By decrypting the digital signature with the corresponding public key, one can ensure the authenticity of the data. The hash can verify the integrity of the data. Let’s see how it happens.

Let’s assume that Alice sends a message to Bob. When Bob receives the message from Alice, he would want to do two things:

  • Ensure that it was indeed Alice who sent the message (verifying authenticity).
  • Ensure that the message received was the message sent by Alice. In other words, the message was not tampered with during transit (verifying integrity).

So, what Alice can do is hash the message and then encrypt the obtained hash with her private key, producing the digital signature of the message. Bob can then receive both the message and the digital signature and decrypt the digital signature with Alice’s public key. If he can decrypt the digital signature using Alice’s public key, then that proves that it was Alice who sent it. Once Bob decrypts the signature, he will get the hash of the message. Bob can then hash the message he received and compare this hash with the hash obtained from the digital signature. If both the hashes are the same, then Bob can confirm that no one has tampered with the message.

In this article, we saw how hashing and asymmetric encryption work and how we use them to produce digital signatures. We shall see how we use them in blockchain to address the challenges associated with decentralized transactions in subsequent articles. In the next article, we shall start to see how blockchain transactions work.

1 Comment

Leave a Reply

placeholder="comment">