A Blockchain Primer › Module 2 › Lesson 2.4

Lesson 2.4: Your Public Key Is Your Account — Keys, Signatures, and Authorization

  • #1. The Core Question
  • #2. An Everyday Analogy
  • #3. Core Concepts Explained
  • #4. Diagrams
  • #5. Key Takeaways
  • #6. Quiz

The last lesson used hashes to identify data. This lesson takes on a different problem. In a system that's open to everyone, how do you give each user an account anyone can identify, make sure only the owner can spend what's in it, and let the owner prove "I agree to this" with a digital signature?

1. The Core Question

If an account address is public, like a house number, and anyone can send things to it, why can't anyone take things out of it too?

This lesson answers two questions: What exactly are the public key and the private key? And how do they work together so an account can receive assets publicly while only the owner can authorize spending them?

The short version: The public key is the account's public identifier. The private key is the control that only the owner knows. A digital signature ties "I agree to this" to one specific transaction.

2. An Everyday Analogy

The Mailbox: Anyone Can Drop a Letter In, Only the Owner Can Open It

An old-fashioned mailbox has a mail slot. Anyone who knows the address can drop a letter in, but taking letters out takes the key the owner carries.

This setup has two key parts:

  • The address is public. Other people can find it and put things inside.
  • The key is private. Only the owner can open the box and take out what's inside.

A blockchain account works a lot like this mailbox. The account address is public, and anyone can send assets to it. But to move the assets inside, you have to hold the matching private key.

Email Address and Email Password

You can give your email address to anyone, and they can send you mail. That doesn't let them log into your inbox, read your mail, or send messages as you. The email address is the public identifier. The password is the control.

The public key and private key work in a similar way, with one important difference. You usually choose your own email password, while a key pair is generated by cryptography software as two keys that match each other mathematically.

The Handwritten Signature

When you sign a paper document, you're saying two things: I confirm what this document says, and I agree to carry it out. A handwritten signature counts as evidence because everyone's handwriting is unique. If someone changes the document's contents afterward, the signature and the document no longer match.

A digital signature is the digital version of a handwritten signature. Instead of handwriting, it relies on cryptography.

3. Core Concepts Explained

3.1 What Cryptography Is For

The main goal of cryptography is to keep data safe from people who shouldn't have access to it. It's like door locks and safes in the real world: if you have the key, you can open them, and if you don't, you can't.

In the digital world:

  • Encryption turns the original data into something unreadable.
  • Decryption turns that back into the original data.
  • What encryption produces is called ciphertext.

Decrypting with the wrong key usually gives you a pile of meaningless characters. It doesn't give away the original.

3.2 Symmetric Cryptography: One Key for Both Directions

Symmetric cryptography uses the same key to encrypt and decrypt. The upside is that it's simple. The downside is getting the key to the other person. If I want to send you an encrypted message, we first have to share the same key safely. If the key leaks along the way, the message isn't safe anymore.

3.3 Asymmetric Cryptography: A Pair of Complementary Keys

Asymmetric cryptography uses a pair of keys that work together:

  • One is the private key. The owner keeps it and never makes it public.
  • The other is the public key, which can be shared with everyone.

The key rule: whatever one key encrypts, only the other key can decrypt. The key that did the encrypting can't decrypt it.

3.4 Two Directions of Use

This key pair can be used in two opposite directions.

Direction one: encrypt with the public key, decrypt with the private key. Anyone who has your public key can encrypt a message and send it to you, and only whoever holds the matching private key can decrypt and read it. This solves the problem of sending information safely to the private key holder.

Direction two: process with the private key, verify with the public key. The private key holder runs the information through a processing step with the private key, and anyone with the matching public key can verify the result. This solves the problem of proving a message really came from a particular person. This direction is the foundation of digital signatures.

3.5 How Blockchain Uses the Public and Private Keys

Blockchain mainly puts asymmetric cryptography to work in two places.

First, identifying accounts. An account needs a public identifier so others can send assets to it. In the simplified model, you can think of the account identifier as the public key. This public identifier is also commonly called an address. The address can be public because it only answers "where do I send this?" It doesn't answer "who can take it out?"

Second, authorizing transactions. Only the account owner can agree to move assets out. The owner creates a proof with the private key, and everyone else checks that proof with the public key. That way, anyone verifying the transaction can confirm it was really authorized without ever knowing the private key.

Keep two ideas separate here:

  • The public key answers "whose account is this, and where do I send it?"
  • The private key answers "I agree to this transfer out."

Publishing your public key won't cost you your assets. Leaking your private key is what hands control to someone else.

3.6 What a Digital Signature Must Satisfy

On a blockchain, a digital signature usually has to meet four requirements:

  1. It shows the account owner agrees to the specific contents of the transaction.
  2. It's valid only for this transaction and can't be reused to authorize another one.
  3. Only whoever holds the matching private key can create it.
  4. Other nodes can verify it easily.

The first two depend on the signature being tied to the transaction contents. The last two depend on the signature being created with the private key and verified with the public key.

3.7 Generating a Signature: Four Steps

Say account A wants to send assets to account B. A's signing process breaks into four steps.

Step one: write out the transaction. The transaction includes the sending account, the receiving account, the amount, the time, the fee, and so on, but not the signature itself yet.

Step two: compute the transaction hash. Run all the transaction data through the hash function to get a digital fingerprint of exactly what this transaction says.

Step three: process the hash with the private key. Think of this as running a signing operation on the transaction hash with A's private key, which produces a signature value.

Step four: attach the signature to the transaction. The transaction data and the signature are submitted together as a "signed transaction."

The signature ties two things together at once:

  • The transaction contents, because the signature is based on the transaction hash.
  • The private key holder, because only the matching private key can create the signature.

3.8 Verifying a Signature: Three Steps

When other nodes receive a signed transaction, they run three checks.

Step one: compute the transaction hash themselves. The node hashes everything in the transaction data except the signature.

Step two: process the signature with the public key. The node runs the signature through a processing step using the sending account's public key and gets a hash value.

Step three: compare the two hash values.

  • If they match, the signature really was created by the matching private key, and nobody has changed the transaction contents.
  • If they don't match, the signature is invalid or someone has changed the transaction contents.

The verifier doesn't need to know the private key. The public key and the signature are enough to run the check.

3.9 How Signatures Catch Tampering — and Why They Can't Be Reused

Say someone intercepts a signed transaction and changes the receiving account or the amount. When the verifying node recomputes the transaction hash, it gets the fingerprint of the changed contents. But the signature carries the fingerprint of the contents as they were when the original sender signed. The two fingerprints don't match, so verification fails.

That shows two things at once:

  • The signature is tied to the original transaction contents, so changing the contents breaks the signature.
  • The forger doesn't have the private key and can't create a new valid signature for the changed transaction.

If a signature were tied only to the private key and not to the transaction contents, an attacker could copy A's signature from a small transaction onto a big one. Digital signatures use the transaction hash to tie the signature to specific contents. The signature is valid only for this transaction. Switch to a different transaction, and the hash is different, so the signature no longer matches. That's why you can't use a signature to authorize some other transaction.

3.10 What a Signature Can Prove — and What It Can't

A digital signature can prove:

  • The matching private key holder really did authorize this transaction.
  • Nobody has changed the transaction contents since it was signed.

A digital signature can't prove, on its own:

  • Whether the account has enough balance.
  • Whether the transaction follows the business rules.
  • Whether the recipient really exists.
  • Whether this transaction will end up being accepted.

So when nodes validate a transaction, they can't look only at the signature. They also have to check formal correctness and semantic correctness, such as balance, amount, and double-spending. The signature handles authorization. It doesn't make the transaction fully valid.

3.11 What a Wallet Does

In practice, users usually don't juggle long strings of keys by hand. Wallet software handles it:

  • It generates accounts and key pairs.
  • It stores private keys.
  • It creates transactions.
  • It authorizes transactions with the private key.

How secure a wallet is depends largely on how well it protects the private key. If the private key leaks, someone else can pose as the account owner.

4. Diagrams

Figure 2-4-1: The Two Directions of Asymmetric Cryptography

Encrypt with the public key and decrypt with the private key; process with the private key and verify with the public keyEncrypt with the public key and decrypt with the private key; process with the private key and verify with the public key
Figure 2-4-1 Encrypt with the public key and decrypt with the private key; process with the private key and verify with the public key
Click to enlarge

Figure 2-4-2: From Signing to Verification

The transaction gets hashed first and then signed; the verifier recomputes the hash and comparesThe transaction gets hashed first and then signed; the verifier recomputes the hash and compares
Figure 2-4-2 The transaction gets hashed first and then signed; the verifier recomputes the hash and compares
Click to enlarge

5. Key Takeaways

  • Symmetric cryptography uses the same key to encrypt and decrypt. Asymmetric cryptography uses a pair of complementary keys.
  • The public key can be public, and the private key has to stay secret. Publishing your address won't let anyone take your assets. Leaking your private key is what costs you control.
  • Encrypt with the public key and decrypt with the private key to deliver something confidentially. Process with the private key and verify with the public key to prove where something came from.
  • A digital signature ties the transaction contents and the private key holder together: the private key creates the signature, and the public key verifies it.
  • Generating a signature: write out the transaction, compute the hash, process the hash with the private key, and attach the signature to the transaction.
  • Verifying a signature: recompute the transaction hash, process the signature with the public key, and compare the two hashes.
  • Change the transaction contents and the signature stops matching. The forger has no private key and can't sign again.
  • A signature proves who authorized the transaction. It doesn't prove the balance is enough or that the transaction will pass the business rules.

6. Quiz

Part 1: Single Choice (1–4)

Question 1

How many keys does asymmetric cryptography use?

A. One, shared for encryption and decryption
B. Two complementary keys, each used in a different direction
C. Three: one each for encryption, decryption, and signing
D. No keys at all

Show answer

Answer: B

Explanation: Asymmetric cryptography uses a pair of complementary keys for different directions, either encryption and decryption or signing and verification. It doesn't use one shared key.

Question 2

In the blockchain account model, what is the public key closest to?

A. A password only the owner knows
B. A public account identifier that others can send assets to
C. A key that has to be kept secret
D. The transaction fee

Show answer

Answer: B

Explanation: The public key is the account's public identifier, which others can send assets to. The private key is the control.

Question 3

When generating a digital signature, what should the first step be?

A. Attach the signature to the transaction
B. Write out the transaction contents, without the signature itself
C. Publish the private key
D. Change the transaction amount to zero

Show answer

Answer: B

Explanation: You have to write out the transaction contents first so you can compute the hash and create the signature. The signature itself isn't part of the hash that gets signed.

Question 4

When verifying a signature, what does the verifier use to process the signature?

A. The sending account's private key
B. The sending account's public key
C. The receiving account's private key
D. Any random key

Show answer

Answer: B

Explanation: The verifier processes the signature with the sending account's public key, which proves the signature came from the matching private key without the verifier ever needing to know that private key.

Part 2: Multiple Choice (5–7)

Question 5

Which statements about the two directions of asymmetric cryptography are correct?

A. Content encrypted with the public key can be decrypted with the private key
B. Content processed with the private key can be verified with the public key
C. You can swap the public and private keys around however you like
D. One direction is for confidentiality and the other is for proving where something came from

Show answer

Answer: A, B, D

Explanation: What the public key encrypts, the private key can decrypt. What the private key processes, the public key can verify. One direction is for confidentiality and the other is for proving origin. C is wrong because swapping the keys around freely creates security risks.

Question 6

Which requirements does a digital signature usually have to meet?

A. It shows the owner agrees to the specific transaction contents
B. It's valid only for this transaction
C. Only the matching private key holder can create it
D. Anyone can verify it easily

Show answer

Answer: A, B, C, D

Explanation: All four are basic requirements for digital signatures used to authorize transactions.

Question 7

When verifying a signed transaction, what does a node usually do?

A. Recompute the hash of the transaction data
B. Process the signature with the sending account's public key
C. Compare the two hash values
D. Just trust the sender when they say "I already signed it"

Show answer

Answer: A, B, C

Explanation: Verification recomputes the hash, processes the signature with the public key, and compares the results. You can't trust the sender's word on its own.

Part 3: True or False (8–9)

Question 8

True or false: once the public key is published, anyone can take the assets straight out of the account.

Show answer

Answer: False

Explanation: The public key or address is a public identifier that only handles receiving. Controlling the assets takes the private key.

Question 9

True or false: even after the signature checks out, nodes still need to check business rules such as balance, amount, and double-spending.

Show answer

Answer: True

Explanation: The signature only handles authorization. Nodes still have to check formal, semantic, and business rules such as balance and double-spending.

Part 4: Scenario Analysis (10)

Question 10

User A uses the private key to sign a transaction: "transfer 10 points to B." An attacker intercepts it, changes the recipient to C and the amount to 100, and broadcasts it again.

Answer the following:

  1. Without A's private key, can the attacker create a valid signature for the changed transaction?
  2. What will nodes find when they verify it?
  3. If the attacker keeps the original signature, where do the two hashes the node compares come from?
Show answer

Answer:

  1. No. A valid signature has to be created with A's private key. Without it, the attacker can't produce a matching signature for the changed transaction.
  2. The node recomputes the hash of the changed transaction and gets a value that's different from the original hash carried in the signature, so the signature fails verification.
  3. One hash comes from the node recomputing the hash of the changed transaction contents. The other comes from processing the original signature with A's public key. The mismatch exposes the tampering.