Lessons 1/4 · 15 min
A key pair: a secret and its public counterpart
The starting question
You send 5,000 CFA francs by mobile money. The operator asks for your PIN and checks it is right: to do that, it must know the secret (or hold what is needed to check it). If someone at the operator is dishonest, your secret is at risk.
On an open network there is no trusted operator. You need a way to prove "it is really me" without ever handing the secret to the person who checks. That is the purpose of a key pair.
The concept
A key pair is two linked numbers:
- the private key: a secret number drawn at random. It is 32 bytes (256 bits) for common elliptic curves such as P-256 or Ed25519;
- the public key: computed from the private key by a one-way operation. You can publish it.
"One-way" means: going from private key to public key is fast; going back is, as far as current knowledge goes, infeasible for well-chosen keys. This is not an absolute mathematical proof: it is a hardness assumption (the elliptic-curve discrete logarithm) that experts have been testing for decades. A large enough quantum computer would break that assumption; none exists today, but it is a known limit.
How many private keys are possible?
A 256-bit private key can take about 2^256 ≈ 1.16 × 10^77 values. Two people drawing at random will not land on the same one, provided the randomness is of cryptographic quality. A weak generator (for example a browser's Math.random) makes the key guessable. Your browser uses the operating system's generator for this, not Math.random.
Two algorithm families in this workshop
| ECDSA P-256 | Ed25519 | |
|---|---|---|
| Private key | 32 bytes | 32 bytes (seed) |
| Signature (raw form) | 64 bytes | 64 bytes |
| Used here | browser tool | independent lab |
The course catalogue names ed25519 for the local lab; the browser tool instead uses ECDSA on the P-256 curve because that is what the browser's cryptography API (WebCrypto) offers everywhere. The ideas are the same: a private key signs, a public key verifies. Bitcoin uses another curve (secp256k1); Ethereum too. The concepts transfer, the bytes do not.
Your turn
Open the tool below and generate a key pair. Note that the private key is never displayed: it stays in your browser's memory. Export the public key: it is base64 text you could send to anyone.
What this does NOT guarantee
Owning a key pair says nothing about who you are. Anyone can generate a thousand in a second. A public key is just a number; tying it to a person or a company takes something else (see the next lesson).
Recap
- The private key is a large secret random number; the public key follows from it in one direction only.
- That one-way property is a hardness assumption, not an absolute proof.
- A key pair proves no identity by itself.
Interactive tool
ECDSA P-256 signature
Generate a key pair in your browser, sign a message, then verify the signature.
The private key is created with extractable: false: the browser keeps it in memory and never lets it be exported, and it is neither displayed nor stored. It lives only in this tab: reloading the page loses it.
Public key (SPKI, base64)
No key yet. Generate a pair to sign.Signature (base64, P1363 format: r ‖ s, 64 bytes)
…ECDSA with SHA-256 on the P-256 curve. WebCrypto returns r and s concatenated (32 + 32 bytes), not DER encoding.
