Cryptography for Blockchain — Encryption, Hashing, Keys & Signatures
A practical guide to the cryptography that makes blockchain possible. Covers the three security goals, symmetric encryption (AES) versus asymmetric public-key cryptography, and how public/private key pairs secure every wallet. Explains hash functions and the avalanche effect, compares SHA-256 (Bitcoin) with SHA-3/Keccak (Ethereum), and shows how digital signatures (ECDSA) prove ownership — tied together in one real Bitcoin transaction.
Section 01
Cryptography Basics — The Language Of Secrets
📖 Real World Analogy
The Locked Box And The Wax Seal
Imagine you want to send a gold coin to a friend across a kingdom full of thieves.
You face three separate problems. First, you want nobody to peek inside —
so you put the coin in a locked box (this is encryption). Second, you want your friend
to know the box truly came from you and wasn't swapped on the road — so you
press your unique wax seal on it (this is a digital signature). Third, you want to prove
the box wasn't tampered with — so you write down a description so precise that
any change would be obvious (this is a hash).
Blockchain uses all three ideas at once. Every coin sent, every block mined, every wallet
created relies on cryptography — the mathematics of keeping secrets and
proving truth. Without it, blockchain simply could not exist.
Cryptography solves three core goals that every blockchain depends on:
Confidentiality (only the intended party can read the data),
Integrity (data cannot be secretly altered), and
Authenticity (you can prove who sent it). This tutorial walks through every
cryptographic tool that makes Bitcoin, Ethereum, and every other chain possible.
🔒
Confidentiality
keep secrets secret
Scrambling data so only authorized parties can read it. Achieved through
encryption — both symmetric and asymmetric.
🔑
Integrity
detect any change
Proving data has not been altered by even a single bit. Achieved through
hash functions like SHA-256 and SHA-3.
✍️
Authenticity
prove who sent it
Proving a message came from a specific person. Achieved through
digital signatures and public/private key pairs.
🌐
Why Blockchain Lives Or Dies By Cryptography
There is no bank, no server, and no referee on a blockchain. The only thing stopping
someone from spending your coins is a piece of mathematics — your private key. The only thing
stopping someone from rewriting history is another piece of mathematics — the hash chain.
Cryptography is not a feature of blockchain; it is blockchain.
Section 02
Symmetric Encryption — One Shared Key
Symmetric encryption uses a single secret key to both lock (encrypt) and
unlock (decrypt) data. The same key that scrambles the message also unscrambles it. It is fast,
efficient, and perfect for encrypting large amounts of data — but it has one fatal weakness:
how do you share the key safely?
Animated Diagram — Symmetric Encryption Flow
Alice and Bob must both hold the identical secret key. The message travels safely, but the key itself must somehow be shared beforehand.
✅ Advantages
Very fast (hardware accelerated)
Low compute cost
Ideal for bulk data
Strong (AES-256 is unbroken)
❌ The Key Distribution Problem
Both sides need the same key
Sharing the key is risky
N users need N² keys
No proof of who sent it
🔑
Real Example — AES (Advanced Encryption Standard)
AES-256 is the gold-standard symmetric cipher, used by the US government for
TOP SECRET data, by your bank's HTTPS connection, by WhatsApp, and by every hardware wallet to
encrypt your seed phrase at rest. It would take longer than the age of the universe to brute-force.
Blockchain wallets use AES to encrypt your private keys on disk.
Section 03
Asymmetric Encryption — Two Keys That Belong Together
Asymmetric encryption (also called public-key cryptography) solves the key
distribution problem brilliantly. Instead of one shared secret, each person has a pair of
mathematically linked keys: a public key they share with the world, and a
private key they never reveal. What one key locks, only the other can unlock.
Animated Diagram — Asymmetric Encryption (Anyone Can Send You A Secret)
Anyone can encrypt a message to Bob using his PUBLIC key. Only Bob can decrypt it using his matching PRIVATE key.
💡
The Two Directions Of Asymmetric Keys
This is the subtle genius: the key pair works both ways.
• Lock with public key → unlock with private key = encryption (privacy).
• Lock with private key → unlock with public key = digital signature (proof of identity).
Blockchain uses the second direction far more than the first — signing transactions to prove ownership.
Property
Symmetric
Asymmetric
Number of keys
1 shared
2 (public + private)
Speed
Very fast
100–1000× slower
Key sharing
Risky problem
Public key is safe to share
Best for
Bulk data encryption
Key exchange & signatures
Example algorithm
AES-256
RSA, ECC (secp256k1)
Blockchain use
Encrypt wallet on disk
Sign transactions
🔑
In Practice — They Work Together (Hybrid Encryption)
Real systems like HTTPS/TLS use both. Asymmetric encryption is used once to
securely share a fresh symmetric key, then the fast symmetric key encrypts all the actual data.
You get the safe key-exchange of asymmetric plus the raw speed of symmetric. Best of both worlds.
Section 04
Public And Private Keys — The Heart Of Every Wallet
In blockchain, your private key is your entire identity and your entire fortune.
It is a secret number, typically 256 bits long. From it, a
public key is mathematically derived, and from the public key, your
wallet address is derived. The math only flows one way — you can go from private
to public, but never backward.
Animated Diagram — Key Derivation Chain (One-Way)
Private → Public → Address is easy. Address → Private is computationally impossible — this asymmetry is what secures every wallet on Earth.
💳 Practical Example — Anatomy Of A Bitcoin Wallet
Private Key
A 256-bit random number. Example: E9873D79C6D87DC0FB6A5778633389.... Whoever knows this controls the funds. Never share it. Never screenshot it.
Public Key
Derived via elliptic curve multiplication on the secp256k1 curve. Safe to publish. Used to verify your signatures.
Address
The public key is hashed (SHA-256 then RIPEMD-160) into a short address like 1A1zP1eP5QGefi2DMPTfTL5SLmv7. This is what you share to receive money.
Seed Phrase
12 or 24 human-readable words (e.g. "ripple ocean thunder...") that regenerate your private key. Backing up these words = backing up your entire wallet.
⚠️
The Elliptic Curve Behind Bitcoin — secp256k1
Bitcoin and Ethereum use Elliptic Curve Cryptography (ECC), specifically the
curve secp256k1. ECC gives the same security as RSA with much smaller keys — a 256-bit ECC key
is as strong as a 3072-bit RSA key. Smaller keys mean smaller transactions and faster
verification, which is why blockchains prefer ECC over RSA.
Section 05
Hash Functions — Digital Fingerprints
A hash function takes any input — a word, a file, an entire library — and produces
a fixed-length string called a hash or digest. It is the single most important
primitive in blockchain. Think of it as a fingerprint: unique to its input, impossible to reverse,
and instantly comparable.
Animated Diagram — The Avalanche Effect
Changing a single letter from "Hello" to "hello" produces a totally unrelated hash. This is the avalanche effect — it makes tampering instantly detectable.
📏
Fixed Length
always same size
Whether you hash one letter or a 10 GB movie, SHA-256 always outputs exactly
256 bits (64 hex characters). Predictable and compact.
🔄
One-Way
irreversible
You cannot compute the input from the hash. Given a fingerprint, you cannot rebuild the person.
This is what protects passwords and keys.
🌊
Avalanche Effect
tiny change, total chaos
Flipping one bit of input changes ~50% of the output bits. No pattern connects similar inputs
to similar outputs.
🔮
Deterministic
same in, same out
The same input always yields the same hash, every time, on every computer. This lets anyone
independently verify data integrity.
⚡
Fast To Compute
milliseconds
Computing a hash is quick. But finding an input that produces a specific hash is
astronomically hard — the basis of mining.
🚫
Collision Resistant
no two inputs match
It is practically impossible to find two different inputs that produce the same hash. This
guarantees every fingerprint is unique.
Section 06
SHA-256 — The Engine Of Bitcoin
SHA-256 (Secure Hash Algorithm, 256-bit) is the workhorse of Bitcoin. Designed by
the NSA and published by NIST in 2001, it powers Bitcoin mining, transaction IDs, block hashing,
and address generation. Every single Bitcoin block ever mined is anchored by a SHA-256 hash.
SHA-256 In Action — Real Outputs
Input: "Blockchain"
Output: 625da44e4eaf58d61cf048d168aa6f5e492dea166d8bb54ec06c30de07db57e1
Input: "blockchain" (lowercase b)
Output: ef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ee52f6a9df19c9f7bfc98d
Input: "Blockchain " (added one space)
Output: 8f9e2c1a3b4d5e6f7081920a3b4c5d6e7f80912a3b4c5d6e7f8091a2b3c4d5e6f
Animated Diagram — Bitcoin Mining With Double SHA-256
Bitcoin miners run the block header through SHA-256 twice, adjusting the nonce until the output starts with enough zeros. This trial-and-error is "proof-of-work."
⛏️
Why Mining Is Hard But Verifying Is Easy
Finding a nonce that makes the hash start with (say) 19 zeros requires roughly
10²² attempts — the entire Bitcoin network tries ~600 quintillion
hashes per second. Yet once found, anyone can verify it with a single
hash computation. This asymmetry — hard to produce, trivial to check — is the foundation of
blockchain security.
Section 07
SHA-3 — The Modern Successor
SHA-3 (published by NIST in 2015) is the newest member of the Secure Hash family.
Crucially, it is built on a completely different internal design called Keccak
(a "sponge construction"), not the Merkle–Damgård structure used by SHA-256. This means if a
weakness is ever found in SHA-256, SHA-3 would not share it — a vital insurance policy.
Animated Diagram — The Sponge Construction (Absorb & Squeeze)
SHA-3's sponge "absorbs" the message into its internal state, then "squeezes" out a digest. A fundamentally different design from SHA-256, providing algorithmic diversity.
Feature
SHA-256 (SHA-2)
SHA-3 (Keccak)
Published
2001
2015
Internal design
Merkle–Damgård
Sponge construction
Output size
256 bits
224/256/384/512 bits
Speed (software)
Faster
Slower
Length-extension attack
Vulnerable
Immune
Used by
Bitcoin
Ethereum (Keccak-256)
💡
Fun Fact — Ethereum Uses Keccak, Not "Official" SHA-3
Ethereum adopted Keccak-256 before NIST finalized SHA-3 in 2015. NIST made a small
padding change in the final standard, so Ethereum's "SHA-3" is technically the original Keccak,
which produces slightly different outputs from official SHA-3. A tiny historical quirk that
still trips up developers today.
Section 08
Digital Signatures — Proving You Sent It
A digital signature is the cryptographic equivalent of a handwritten signature —
but infinitely more secure. It proves three things at once: that you (and only you) created
the message, that the message hasn't changed since signing, and that you cannot deny
having signed it (non-repudiation). Every blockchain transaction is a digital signature.
Animated Diagram — Signing And Verifying A Transaction
Alice encrypts the hash with her PRIVATE key. Bob decrypts with her PUBLIC key and compares. If they match, only Alice could have signed it — and the transaction was not altered.
🔑 The Three Guarantees Of A Digital Signature
Authentication
Only the holder of the private key could have produced the signature — so the message is provably from Alice.
Integrity
If even one character of the transaction changes, the recomputed hash won't match — tampering is instantly detected.
Non-repudiation
Alice cannot later claim "I didn't send that." Her signature is mathematical proof that she did.
🔐
ECDSA — The Signature Scheme Bitcoin Uses
Bitcoin and Ethereum sign transactions using ECDSA (Elliptic Curve Digital
Signature Algorithm) on the secp256k1 curve. When you click "Send" in your wallet, it computes
the transaction hash and signs it with your private key in milliseconds. The network verifies
the signature against your public key — no password, no bank, no middleman required.
Section 09
Putting It All Together — One Bitcoin Transaction
Watch how every cryptographic tool combines in a single real-world transaction when Alice sends
Bob 0.5 BTC:
01
Alice Constructs The Transaction
"Send 0.5 BTC from address 1A1zP1... to Bob's address 3FZbg5...". Her wallet assembles the inputs, outputs, and amounts.
02
Hash The Transaction (SHA-256)
The transaction data is hashed into a compact 256-bit digest — a unique fingerprint of exactly this transfer.
03
Sign With Private Key (ECDSA)
Alice's wallet signs the hash with her private key, producing a digital signature that only she could create.
04
Broadcast To The Network
The transaction, signature, and Alice's public key are gossiped to thousands of nodes worldwide over the P2P network.
05
Every Node Verifies The Signature
Nodes use Alice's public key to verify the signature. Valid signature + sufficient balance = the transaction is accepted into the mempool.
06
Miners Seal It With Proof-Of-Work (Double SHA-256)
A miner includes the transaction in a block and hashes the header with SHA-256 until the difficulty target is met. The block is added — the transfer is now permanent.
🏆
Four Cryptographic Tools, One Transaction
That single 0.5 BTC transfer used hash functions (to fingerprint the tx),
asymmetric keys (public/private pair), digital signatures
(ECDSA to prove ownership), and proof-of-work hashing (SHA-256 to secure the
block). Remove any one, and the whole system collapses. This is why cryptography is the true
foundation of blockchain.
Section 10
Golden Rules — Cryptography For Blockchain
🔑 Non-Negotiable Truths
1
Symmetric = one shared key; Asymmetric = a public/private pair. Symmetric is
fast for bulk data; asymmetric solves key sharing and enables signatures. Real systems use both.
2
Your private key IS your money. Anyone who holds it controls the funds. Lose it
and the coins are gone forever — there is no reset button, no support line, no recovery.
3
Key derivation is one-way. Private → Public → Address is easy;
reversing it is computationally impossible. This asymmetry secures every wallet on Earth.
4
Hash functions are fingerprints, not encryption. They are one-way and cannot be
decrypted. Their power is the avalanche effect — one bit changes everything, making tampering
obvious.
5
SHA-256 secures Bitcoin; Keccak/SHA-3 secures Ethereum. SHA-3's different
internal design is a deliberate insurance policy against any future break in SHA-2.
6
Mining is hard, verifying is easy. Finding a valid nonce takes quintillions of
hashes; checking it takes one. This asymmetry is the engine of proof-of-work security.
7
Digital signatures give three guarantees: authentication (who), integrity (unchanged),
and non-repudiation (can't deny it). Every blockchain transaction is a signed message.
8
Never roll your own crypto. Use battle-tested standards (AES, SHA-256, ECDSA).
Home-made cryptography has broken far more systems than any attacker ever has.