Cryptography is the backbone behind the blockchain’s security. With Bitcoin’s launch in 2009 came the arrival of the blockchain, which claimed to be nearly impossible to compromise or hack into. Over a decade later, the blockchain has indeed proven to be highly secure, but not perfect.
Some factors that ensure the blockchain’s resilience to hacking and malicious attacks are its distributed design, consensus-based transaction verification, and immutability of records. The main underlying factor that makes blockchain technology highly secure is cryptography; specifically, secure digital communications based on cryptography.
What Is Cryptography?
Cryptography is an interdisciplinary field of study aimed at developing secure private communications in the presence of potential malicious third parties. Simply speaking, it is a way to encode messages sent between parties so that only the sender and the receiver can understand the message.
What is cryptography in blockchain?
Within the context of blockchain technology, cryptography is used for a number of purposes:
- To develop the secure exchange of data between two transacting nodes, such as a wallet sending cryptocurrency to another user’s wallet
- To verify transactions on the network by mining nodes
- To ensure the immutability of records on the blockchain
- For specific application purposes, such as ensuring data confidentiality in smart contracts
Blockchain Encryption and Decryption
There are two key components to a cryptographic exchange of data:
- Encryption, which is the process of turning a plain-text message into a cryptic form that cannot be read or understood by third parties. The sender of the message encrypts it for secure transmission.
- Decryption, which is the process of turning the encrypted message back into plain-text form. The receiver decrypts the message when it has been safely delivered to them.
The algorithm that is used for encrypting and decrypting the data is called a cipher. An example of a primitive cipher could be when each letter in a message exchange is replaced by a digit referring to that letter’s position in the alphabet, such that 01 refers to A, 02 to B, 26 to Z, and so on. For example, in this simple cipher, “08-09” would refer to “Hi”.
The actual encryption of the message from “Hi” to “08-09”, and subsequent decryption from “08-09” to “Hi”, is done using a cryptographic key — a piece of data that encrypts and decrypts messages based on an algorithm/cipher.
Thankfully, the blockchain and other modern computerized systems use far more sophisticated and secure encryption algorithms than our simple example. We will cover these further in the article.
The Main Types of Cryptographic Encryption
There are three main types of cryptographic encryption/decryption used by modern systems:
Symmetric encryption
Under this form of encryption, the same key is used both to encrypt and to decrypt communication between parties. In our simplified example, the same key (the mapping from letters to numbers) is needed to turn “Hi” into “08-09”, and then to decrypt “08-09” back to “Hi”.
Symmetric encryption is the simplest of the three forms of modern encryption. Its advantage is the high speed of execution. However, symmetric encryption has a serious limitation, if the key becomes known to malicious outsiders, the entire communication will be compromised. This makes it impractical for use with a decentralized technology such as blockchain.
Asymmetric encryption
also known as public key encryption: This form of encryption uses a pair of keys, a public key and a private key, to secure communication. The public key is used to encrypt the message by the sender, while the private key is used for decryption by the receiver. Both keys belong to the receiver of the communication. The public key can be used by anyone to encrypt a message and send it to the wallet address of the receiver.
In fact, public keys and wallet addresses are closely intertwined concepts. On most public blockchains like Bitcoin (BTC), a wallet address is the hashed version of the user’s public key. When the message is delivered to the wallet, the receiver, then, uses their private key to decrypt and read the message. The receiver’s private key is known only to them, not to the sender nor anyone else on the network. The use of public-private key pairing makes asymmetric encryption a more secure form of cryptographic exchange compared to symmetric, i.e. single key encryption.
Hash function encryption
Considered a highly secure encryption type, hashing does not use keys at all. Hashing uses an algorithm to take an input of any length and produce an output of a fixed length.
There are a number of different hash functions in use, of which only some (known as “cryptographic hash functions”) are considered secure enough for cryptographic purposes. For example, Bitcoin uses the SHA-256 function, while Ethereum’s hash encryption is based on KECCAK-256.
Cryptographic hash functions possess a number of characteristics that make them ideal for secure encryption:
- They have extremely low chances of collisions occurring. This means that the chances of two different inputs leading to the same hashed output are astronomically tiny, making brute force attacks impossible
- The original message cannot be reverse-engineeredfrom the hash output
- They are deterministic, i.e. any input will produce the same output when run through the hash function
- Even a tiny change made to the input, such as flipping a single bit from 0 to 1, will produce a completely different output hash
Of the three encryption types, symmetric encryption is virtually never used on the popular established blockchain networks. Asymmetric encryption and hashing, however, are both extensively utilized in blockchain technology.
Cryptography Use in Blockchain
Asymmetric encryption is used in blockchain to enable secure node-to-node transactions. Whenever you send or receive crypto coins or tokens to or from another wallet on the network, your transactions are protected with asymmetric encryption.
Hashing encryption has an even more wide-ranging use in the blockchain. One use of hashing is to encrypt users’ public keys into blockchain addresses. When a public key for a new user is created, it is run through a hash function to generate the corresponding wallet address on the network. This adds an extra layer of security to the address system of the blockchain.
Hashing is also used in blockchain mining in Proof-of-Work (PoW) networks. Mining refers to the verification of transactions on the network by participating “miner nodes.” When a transaction on the blockchain occurs, its authenticity must be verified by a number of network users called miners.
Each transaction data block contains a unique number generated through hashing. Miner nodes on the network dedicate considerable computing power to solve a mathematical puzzle in order to find another number, called a “nonce.” Once added to the hash of the block to be verified, the nonce will help complete the verification.
Hashing algorithms, therefore, serve as the backbone of data verification via mining on blockchains. They are also used to tie records on the network into an immutable chain. Each data block on the network contains its own unique hash code and the previous block’s hash.
This ensures that any attempted change to a block of data will require making changes to all the previous blocks in the chain, a task that is impossible for all practical purposes. This chaining through hash codes is a key security feature in blockchain technology.
In addition to the standard core use of asymmetric and hashing cryptography in blockchain, there are specific areas within the blockchain ecosystem where encryption is useful. One such area is smart contracts.
Are smart contracts encrypted?
Due to the public nature of most blockchains, smart contracts are easily viewable by any network participant, and, thus, lack the key feature of confidentiality often sought in contracting. As smart contracts become more common, cryptography based on hashing algorithms will be used more extensively to protect sensitive contractual data.
Blockchain technologies like Hawk are an emerging area of development aimed at ensuring the privacy and confidentiality of blockchain smart contracts. Hawk is a protocol that cryptographically hides key sensitive information in a smart contract from the public’s view on the blockchain. In essence, technologies and protocols like Hawk are all based on some form of hashing cryptography.
Here is a summary of the cryptographic methods commonly used in different aspects of blockchain:
Use in Blockchain | Type of Cryptography |
Transactions between nodes (e.g. buying and selling coins and tokens) | Asymmetric |
Mining/Verification of transactions | Hashing |
Immutability/Security of records on the blockchain | Hashing |
Data protection in smart contracts | Hashing |
Conclusion
Of the three types of cryptographic encryption methods — symmetric, asymmetric, and hashing, blockchain uses the latter two. Symmetric encryption is rarely used in blockchains due to its comparatively poor security characteristics and unsuitability for decentralized applications.
Asymmetric encryption, based on a pairing of public and private keys, is at the heart of ensuring security in user-to-user transactions.
Hashing encryption is used for a number of critical processes that ensure the blockchain’s overall security. Hashing is used in transaction verification through mining; maintaining immutability of records on the blockchain; and also for specialized applications such as ensuring confidentiality and privacy of data in smart contracts. Additionally, hashing is also used in converting public keys into blockchain addresses.
Popular blockchain platforms like Bitcoin or Ethereum use high-grade, secure hashing algorithms, such as SHA-256 and KECCAK-256. The use of these sophisticated algorithms ensures that their blockchains are among the most secure digital networks currently in existence.
At the moment, cryptographic protection of data in smart contracts is a newer area of development for blockchain technology. Cryptography based on hashing algorithms will become increasingly important as smart contracts gain popularity.