Ir al contenido
Londres, Reino Unido · Fundado en 1994
Español

Unit 2: Cryptography for Blockchain

The cryptographic tools that make blockchains work: hash functions, public and private keys, digital signatures, and the wallets used to manage them safely.

Unit 2 of 5 · about 54 minutes

2.1 Hash functions: digital fingerprints

Cryptography is the science of protecting information using mathematics. Blockchains rely on two main cryptographic tools: hash functions and public-key cryptography. This lesson covers hash functions, which act as digital fingerprints for data. You do not need to perform any calculations; the aim is to understand what hashes do and why they are trusted.

What a hash function does

A cryptographic hash function takes any input, whether a single word, a contract or an entire database, and produces a fixed-length output called a hash or digest. The output looks like a long string of random letters and numbers. Bitcoin, for example, uses a hash function called SHA-256, which always produces an output of 256 bits, usually written as 64 hexadecimal characters, regardless of the size of the input.

Essential properties

For a hash function to be useful in security, it must have several properties:

  1. Deterministic: the same input always produces exactly the same hash.
  2. Fast to compute: calculating the hash of any input is quick.
  3. One-way (pre-image resistance): given a hash, it is practically impossible to work out the original input, other than by guessing inputs one after another.
  4. Avalanche effect: a tiny change in the input, such as changing one letter or adding a space, produces a completely different hash with no obvious relationship to the original.
  5. Collision resistance: it is practically impossible to find two different inputs that produce the same hash.

Together, these properties mean that a hash acts as a unique, compact fingerprint. If two people calculate the hash of a document and get the same result, they can be confident they have identical copies.

How blockchains use hashes

  • Linking blocks: as Unit 1 explained, each block contains the hash of the previous block, creating the chain.
  • Summarising transactions: transactions in a block are hashed in pairs, and the results are hashed again in pairs until a single value remains. This structure is called a Merkle tree, and its top value, the Merkle root, is stored in the block header. It allows anyone to prove that a particular transaction is included in a block without downloading every transaction.
  • Proof of work: on some blockchains, creating a block requires finding a hash that meets a difficult target, as Unit 3 explains.
  • Addresses: blockchain addresses are usually derived from public keys using hash functions.
  • Anchoring documents: organisations can record the hash of a document on a blockchain without revealing the document itself. Later, anyone holding the document can recalculate its hash to prove it existed in that form at that time.

Tip: Recording a document's hash on a blockchain proves that the document has not changed since that moment. It does not prove that the document was accurate or that its author was who they claimed to be.

Hashing is not encryption

People sometimes confuse hashing with encryption. Encryption is reversible: data is scrambled with a key and can be unscrambled with the correct key. Hashing is one-way: there is no key, and the original cannot be recovered from the hash. This is why hashes are suitable as fingerprints but not as a way of storing information you will later need to read.

A related point concerns personal data. Hashing a short, predictable value, such as a date of birth or a phone number, does not reliably hide it, because an attacker can simply hash all possible values and compare. Data protection regulators in many countries treat such hashed data as still potentially personal. This matters when deciding what to place on a blockchain, as Unit 5 discusses.

How strong are hash functions?

Well-established hash functions used in major blockchains are considered secure against known attacks with today's computers. Older functions, such as MD5 and SHA-1, have been shown to have weaknesses and should not be used for security purposes. Researchers also study how future quantum computers might affect cryptography. Current analysis suggests that well-designed hash functions are less exposed than some signature schemes, and standards bodies are preparing new "post-quantum" algorithms. This is an area to watch rather than a present-day emergency.

Common mistakes

  • Assuming a hashed value is anonymous simply because it looks random.
  • Treating a recorded hash as proof that a document's contents are true.
  • Using outdated hash functions in new systems.

In practice

Imagine a university wants to let employers verify degree certificates. It could record the hash of each certificate on a blockchain when it is issued. An employer receiving a certificate from a graduate can calculate its hash and check that it matches the recorded value. If anyone has altered the grade or name, the hash will not match. The certificate itself, containing personal details, never needs to be placed on the blockchain.

2.2 Keys and digital signatures

Hash functions show whether data has changed. Public-key cryptography answers a different question: who authorised this? It is the foundation of ownership on a blockchain, because it allows people to prove they control an account without revealing any secret and without a central authority checking passwords.

Public and private keys

In public-key cryptography, also called asymmetric cryptography, each user has a pair of mathematically linked keys:

  • a private key, which is a very large secret number that must be kept confidential;
  • a public key, which is calculated from the private key and can be shared openly.

It is easy to calculate the public key from the private key, but practically impossible to work backwards from the public key to the private key. On most blockchains, a user's address, the identifier others use to send them assets, is derived from the public key, usually by hashing it.

A helpful analogy is a letterbox. The address and slot (like the public key) are visible to everyone, and anyone can post something in. Only the person with the key to the letterbox (like the private key) can open it and take items out.

Digital signatures

When a user wants to make a transaction, such as sending tokens, they create a digital signature. The process works as follows:

  1. The transaction details are prepared, including the recipient, amount and other data.
  2. The user's wallet software uses the private key to produce a signature for those exact details.
  3. The transaction and signature are broadcast to the network.
  4. Any node can use the sender's public key to check that the signature is valid for that transaction.

A valid signature proves three things: that the transaction was authorised by the holder of the private key (authentication), that the details have not been changed since signing (integrity), and that the signer cannot credibly deny having signed it (non-repudiation). Crucially, the private key itself is never revealed.

ItemKept secret?Used for
Private keyYes, alwaysCreating signatures to authorise transactions
Public keyNoVerifying signatures
AddressNoReceiving assets; shared like an account number
SignatureNoProving a specific transaction was authorised

"Not your keys, not your coins"

On a public blockchain, control of assets is entirely determined by control of the private key. Whoever holds the private key can sign transactions and move the assets. There is no password reset, no customer service desk and, in most cases, no way to reverse a transaction. This has two important consequences:

  • If a private key is lost, the assets it controls are usually inaccessible forever.
  • If a private key is stolen, the thief can move the assets, and recovery is very difficult.

Remember: On a blockchain, the private key is the asset owner. Protecting private keys is the single most important security task for anyone holding digital assets.

Signatures in business blockchains

In permissioned blockchains, the same principles apply, but keys are usually linked to verified identities through digital certificates issued by a trusted authority. This means that a signature can be connected to a specific organisation or employee, supporting accountability and audit. Organisations must manage these keys carefully, revoking them when staff leave or when a key may have been exposed.

Pseudonymity and privacy

On public blockchains, addresses are not directly linked to names. However, every transaction is visible, and analysis firms and investigators can often connect addresses to real identities, for example when funds pass through a regulated exchange that has verified its customers. It is therefore more accurate to call public blockchains pseudonymous rather than anonymous. Some blockchains and techniques aim to provide stronger privacy, for example using advanced methods called zero-knowledge proofs, which allow something to be proved true without revealing the underlying data.

In practice

If your organisation is considering accepting or holding digital assets, or joining a business blockchain, ask: who will control the private keys, and how are they protected? What happens if the person responsible leaves or is unavailable? Can a single individual move assets alone, or are several approvals required? These questions about key control are often more important than any question about the blockchain itself.

2.3 Wallets and key management

A wallet is software or hardware that manages private keys and lets users view balances, receive assets and sign transactions. Despite the name, a wallet does not hold coins or tokens. The assets are recorded on the blockchain; the wallet holds the keys that control them. Choosing and managing wallets well is essential for anyone, or any organisation, dealing with digital assets.

Custodial and non-custodial wallets

  • Custodial wallets are provided by a third party, such as an exchange or specialist custodian, which holds the private keys on the customer's behalf. They are convenient and can offer password recovery, but the customer depends on the custodian's security, honesty and solvency. Several high-profile custodial platforms have failed or been hacked, leaving customers unable to access their assets.
  • Non-custodial wallets, often called self-custody, leave the user in full control of their own keys. This removes dependence on a third party but places all responsibility for security and backup on the user.

Hot and cold wallets

Wallets are also described by whether they are connected to the internet:

  1. Hot wallets are connected, such as phone apps, browser extensions or exchange accounts. They are convenient for frequent transactions but more exposed to malware, phishing and hacking.
  2. Cold wallets keep keys offline, for example on a dedicated hardware device or in a securely stored offline system. They are much harder to attack remotely and are commonly used for larger holdings.

A common approach, for individuals and organisations alike, is to keep a small amount in a hot wallet for day-to-day use and the majority in cold storage.

Recovery phrases

Many wallets generate a recovery phrase, also called a seed phrase: a list of typically twelve or twenty-four ordinary words. The phrase can regenerate all the wallet's private keys, so it acts as a master backup. Anyone who obtains the phrase can take everything in the wallet.

Tip: Never type a recovery phrase into a website, email, chat or form, and never share it with anyone claiming to offer support. Legitimate wallet providers and exchanges do not ask for it. Requests for a recovery phrase are a very common feature of scams.

Organisational key management

Organisations holding digital assets, or operating nodes on business blockchains, need stronger controls than individuals. Common practices include:

  • Multi-signature (multisig) wallets: transactions require signatures from several keys, for example any three of five, so that no single person can move funds and the loss of one key is not fatal.
  • Multi-party computation (MPC): a technique that splits signing ability across several parties or devices so that a complete private key never exists in one place.
  • Hardware security modules (HSMs): tamper-resistant devices designed to generate and store keys securely.
  • Segregation of duties: separating the people who initiate, approve and execute transactions, as in traditional finance controls.
  • Documented procedures: covering key generation, backup, storage locations, staff changes and incident response.
  • Regulated custodians: many organisations prefer to use custodians that are authorised and supervised in their jurisdiction.

Common threats

  1. Phishing: fake websites or messages that trick users into revealing recovery phrases or approving malicious transactions.
  2. Malicious approvals: on smart contract platforms, signing an apparently harmless request that actually grants a contract permission to move your tokens.
  3. Address substitution: malware that replaces a copied address with an attacker's address.
  4. Social engineering: impersonating colleagues, support staff or investment advisers to pressure people into acting quickly.
  5. Insider risk: a single employee with unchecked control over keys.

A personal safety checklist

  • Use reputable wallets and download them only from official sources.
  • Store recovery phrases offline, in a secure place, and consider a second secure copy.
  • Check the full recipient address before confirming, and send a small test transaction for large amounts.
  • Read what you are being asked to sign; reject unclear requests.
  • Be very cautious of unsolicited offers, guaranteed returns and pressure to act quickly.

In practice

Consider a small charity that has started receiving donations in a cryptocurrency. Rather than letting one staff member manage a phone wallet, it could use a regulated custodian or a multisig wallet requiring two of three trustees to approve any transfer, convert donations under a written policy, and record the procedure in its financial controls. These steps apply familiar principles of financial governance to a new type of asset.

Case study: Strengthening key controls at a small investment firm

Fenwick Lane Capital, a fictional investment firm, had begun holding a small amount of digital assets for a client fund. An internal audit found that the keys were held in a single hardware wallet kept in the chief technology officer's desk, with the recovery phrase written on a card in the same drawer. Only he knew the PIN.

The audit committee identified three risks: theft of the device and card together, loss of access if he were unavailable, and the possibility that one person could move client assets without approval.

The firm moved the holdings to a regulated custodian using a multi-party computation arrangement. Transfers now require approval from two named staff members out of four, with a further sign-off from compliance above an agreed value. Approved withdrawal addresses are whitelisted in advance, and every transfer is logged and reconciled weekly by the finance team. The procedures were written into the firm's operations manual, and a test withdrawal was carried out to confirm that the process worked before any client assets were moved.

Activity

Imagine you are advising a small business that wants to hold a modest amount of a cryptocurrency for payments. Write a short key management plan covering the type of wallet, who controls the keys, how recovery phrases are stored and how transactions are approved. Identify the single greatest risk your plan is designed to reduce.

Compare with a model answer

A good plan makes clear, justified choices. For example, it might recommend a multisig wallet requiring two of three directors to approve payments, or a regulated custodian, rather than a single staff member's phone wallet. It keeps most funds in cold storage and only small working amounts in a hot wallet.

Recovery phrases are recorded offline, stored in separate secure locations such as a safe, and never photographed or typed into devices. Transactions above an agreed value require dual approval and a check of the recipient address, ideally with a small test payment first. Procedures for staff leaving are included.

The answer names a key risk, such as one person being able to move or lose all funds, and explains how dual control and secure backups reduce it.

Key takeaways

  • Hash functions create fixed-length digital fingerprints; they are one-way, deterministic and highly sensitive to any change in input.
  • Hashes link blocks, summarise transactions in Merkle trees and can prove a document existed unchanged, without revealing its contents.
  • Public-key cryptography lets users prove control of an account with digital signatures while keeping the private key secret.
  • On public blockchains, whoever controls the private key controls the assets, so lost or stolen keys usually mean lost assets.
  • Wallet choices and key management controls, such as cold storage, multisig, segregation of duties and protecting recovery phrases, are central to security.

Unit check

Create a free account to answer the check, save your progress and receive your free certificate.

Create a free account Log in
← Unit 1 Unit 3 →
WhatsApp