Symmetric and asymmetric encryption
Suggest an editA common assumption is that the blockchain "encrypts" your data. In fact, public blockchains do not encrypt transactions, balances, contract storage, or anything else at the protocol level.
Every byte of state on a public chain is readable by anyone running a node (a computer that holds a copy of the chain). Your balance and every transaction you have ever sent are public, and they stay visible permanently.
What protects you is authentication (proving you authorized an action) and integrity (proving data wasn't tampered with). Both come from hashing and from digital signatures, a cryptographic primitive covered in a later lesson.
Encryption still shows up in a few places around a blockchain. One of its two kinds also works with a pair of keys, and the next lessons build on that pair.
Only the holder of the key can reverse encryption
Encryption transforms data using a key so that only someone with the right key can transform it back. The transformed data is called ciphertext and looks like random noise. The original data is plaintext. Without the key, ciphertext is meant to be useless, and with the key it returns to the original byte for byte. The strength of an encryption scheme is how expensive it is to recover the plaintext without the key.
The key is what separates encryption from encoding, which has no key and can be reversed by anyone.
There are two families of encryption schemes that differ in how the key works.
In symmetric encryption there is one key. Whoever has the key can encrypt new data and decrypt existing data.
The standard algorithm here is AES (Advanced Encryption Standard). It is what your operating system uses to encrypt your disk and what password managers use to encrypt their vaults. Symmetric encryption is fast, so it's the right tool for bulk data.
The limitation is key distribution. Symmetric encryption only works if both ends already share the key. If Alice and Bob want to communicate securely and they've never met, how does Alice send Bob the key without an attacker intercepting it? She can't encrypt the key with symmetric encryption, because they don't have a shared key yet. To share the key safely they would already need a secure channel, which is the very thing they are trying to create. This is the problem the other family of encryption was invented to solve.
Asymmetric: a public key removes the delivery problem but is slow
In asymmetric encryption, also called public-key encryption, each participant has a key pair: two mathematically linked keys that work in opposite directions. One key encrypts, the other decrypts.
The participant keeps one key secret (the private key) and publishes the other (the public key) freely. Anyone in the world can take your public key and use it to encrypt a message that only your private key can decrypt. The public key cannot be used to decrypt, only to encrypt.
This solves the key-distribution problem. Bob publishes his public key on his website, and anyone can encrypt a message to him without ever meeting him. Only Bob, holding the private key, can decrypt it.
The price is speed: asymmetric encryption is typically 100 to 1000 times slower than symmetric, depending on the algorithm and the data size, so you wouldn't use it to encrypt a large file. A standard algorithm here is RSA.
In practice the two families are used together, in a pattern called hybrid encryption: asymmetric encryption is used briefly at the start to exchange a fresh symmetric key, and the symmetric key encrypts everything else. TLS, the protocol that protects the connection when your browser opens a website over HTTPS, works this way.
A public chain uses encryption only at its edges
Encryption plays a small and specific role in public blockchains. It shows up in three places:
At rest, in your wallet file. When you install a wallet, the application encrypts your private key on disk using a password you choose. That encryption is symmetric (AES, with the password run through a key-derivation function first). If you forget the password, the wallet file stays unreadable. The blockchain itself doesn't know about this, it's a local security measure done by the wallet software.
In transit, when you talk to a node. When your wallet sends commands to a remote node over the internet, the connection is usually wrapped in TLS. This is standard internet infrastructure, and the blockchain protocol doesn't specify it.
In specialised chains that opt into it. A few chains are designed around encrypted transactions where the amounts and recipients are hidden from public view. These are the exception, and they involve cryptography beyond what plain AES or RSA provide.