Today we are going to explain what hashing and digital signature is in the blockchain.
What is hashing in the blockchain?
Hashing refers to the concept of taking an arbitrary amount of input data, applying some algorithm to it, and generating a fixed-size output data called a hash. The input can be any number of bits that could represent a single character, an MP3 file, an entire novel, a spreadsheet of your banking history, or even the entire Internet.
The point is that the input can be infinitely large. The hashing algorithm can be chosen depending on your needs and there are many publicly available hashing algorithms. The point is that the algorithm takes the infinite input of bits, applies some calculations to them, and produces a finite number of bits. For example, 256 bits.
What can this hash be used for?
A common use for hashes today is for fingerprinting files, also known as verification zones. This means that a hash is used to verify that a file has not been tampered with or modified in any unintended way by the author. If WikiLeaks, for example, publishes a set of files along with their MD5 hashes, whoever downloads those files can verify that they are actually from WikiLeaks by calculating the MD5 hash of the downloaded files, and if the hash does not match what was published by WikiLeaks, then you know that the file has been modified in some way.
How does the blockchain use the hash?
Hashes are used in blockchains to represent the current state of the world. The input is the complete state of the blockchain, i.e. all transactions that have taken place so far and the resulting output hash represents the current state of the blockchain. The hash is used to agree between all parties that the global state is one and the same, but how are these hashes actually calculated?
The first hash is calculated for the first block or Genesis block using the transactions within that block. The sequence of initial transactions is used to calculate a block hash for the Genesis block. For each new block that is subsequently generated, the hash of the previous block, as well as its own transactions, is also used as input to determine its block hash. This is how a blockchain is formed, each new block hash pointing to the block hash that came before.
This hashing system ensures that no transaction in the history can be manipulated because if any part of the transaction changes, so does the hash of the block it belongs to, and any subsequent block hashes as a result. It would be fairly easy to catch any manipulation as a result, since only hashes can be compared. This is great because everyone on the blockchain only needs to agree on 256 bits to represent the potentially infinite state of the blockchain. The Ethereum blockchain is currently tens of gigabytes, but the current state of the blockchain, as of this recording, is this hexadecimal hash representing 256 bits.
What are digital signatures in the blockchain?
Digital signatures, like real signatures, are a way to prove that someone is who they say they are, except that we use cryptography or mathematics, which are more secure than handwritten signatures that can be easily forged. A digital signature is a way to prove that a message comes from a specific person and no one else, such as a hacker.
Digital signatures are used all over the Internet today. Every time you visit a website through ACTPS, you are using SSL, which uses digital signatures to establish trust between you and the server. This means that when you visit Facebook.com, your browser can check the digital signature that comes with the web page to verify that it actually originated from Facebook and not some hacker.
In asymmetric encryption systems, users generate something called a key pair, which is a public key and a private key using a known algorithm. The public key and private key are associated with each other by some mathematical relationship. The public key is intended to be distributed publicly to serve as an address for receiving messages from other users, such as an IP address or home address.
The private key must be kept secret and is used to digitally sign messages sent to other users. The signature is included in the message so that the recipient can verify it using the sender’s public key. In this way, the recipient can be sure that only the sender could have sent this message. Generating a key pair is analogous to creating an account on the blockchain, but without having to register anywhere. Pretty cool. In addition, every transaction executed on the blockchain is digitally signed by the sender.
To tie it all together, there could be no blockchain without hashing and digital signatures. Hashing provides a way for everyone on the blockchain to agree on the current state of the world, while digital signatures provide a way to ensure that all transactions are made only by the rightful owners. We rely on these two properties to ensure that the blockchain has not been corrupted or compromised.