[Certificate Fundamentals Part 2] Cryptography Basics: Symmetric Keys, Public Keys, Key Exchange, Hashes, and Signatures Explained with Diagrams

Certificate Fundamentals Part 2 Cryptography Basics: Symmetric Keys, Public Keys, Key Exchange, Hashes, and Signatures Explained with Diagrams Certificates and PKI

“You encrypt with the public key and sign with the private key… wait, is it the other way around?”
“HTTPS encrypts data with RSA, right?”

Questions like these come up often when talking about certificates. In fact, the second one is wrong. What encrypts the actual data in today’s TLS is not RSA but symmetric encryption.

In Part 1, we saw that TLS protects against the three threats of eavesdropping, tampering, and impersonation with separate components. In Part 2, we look at those components one by one. We use no math and focus on “which component protects what.”

▶ This part is also available as a YouTube video (about 21 min) (it is also embedded at the end of this article).


Symmetric encryption (AES)

Symmetric encryption uses the same key for encryption and decryption. Picture a safe that opens and closes with a single key, with the sender and the receiver both using that same key.

Diagram showing a sender and a receiver holding the same shared key; the ciphertext made by encrypting "Start work at 10:00" with AES cannot be read by an eavesdropper who has no key

It is light and fast, so symmetric encryption still does the encryption of the data itself, both in TLS and in disk encryption (such as BitLocker).

  • The current standard is AES (standardized in 2001 as FIPS 197)
  • It is a block cipher that splits data into 128-bit (16-byte) blocks and encrypts them
  • You choose a key length of 128, 192, or 256 bits
  • Many CPUs have dedicated AES instructions, so it runs very fast

DES, used in the past, was broken because its key was too short, and NIST stopped allowing 3DES (Triple DES) for encryption at the end of 2023.

The weakness of symmetric encryption is how to share the same key with the other party safely (explained later).


Block cipher modes and authenticated encryption

A block cipher such as AES changes character a great deal depending on how the blocks are chained (the mode of operation).

Diagram showing that an original image encrypted with ECB keeps its outline while GCM turns it into static, and that AES-GCM produces ciphertext and a 16-byte tag from plaintext, key, and nonce, with the receiver discarding the data if the tag does not match
ModeHow it worksFeatures and cautionsWhere it is used
ECBEncrypts each block on its ownIdentical plaintext blocks give identical ciphertext, so patterns remainDo not use
CBCMixes in the previous ciphertext block, then encryptsCannot detect tampering; a separate MAC is needed. Attacks that abuse padding have existedTLS 1.2 and earlier, older products
CTREncrypts a counter value and XORs it with the plaintextCan be parallelized and is fast. No tamper detectionA building block of GCM and others
GCM (AES-GCM)CTR + a tag for tamper detectionAuthenticated encryption (AEAD). Reusing a nonce (a one-time value) with the same key breaks itMainstream in TLS 1.2/1.3, IPsec
ChaCha20-Poly1305Stream cipher + MAC (RFC 8439)AEAD. Fast even on devices without dedicated AES instructionsTLS 1.3, smartphones, WireGuard
XTSEncrypts with a value that changes by position on the diskFor stored data. No tamper detectionDisk encryption

As the penguin in the figure shows, ECB leaks patterns, so it is not used. NIST’s draft (SP 800-131A Rev.3) proposes ending the use of ECB for encryption.

Today’s mainstream is authenticated encryption (AEAD). It performs encryption and tamper detection in a single operation and creates a tag along with the ciphertext. If the tag does not match on the receiving side, the data is discarded. This tag is what protects the “integrity (not rewritten)” from Part 1.

TLS 1.3 can use only AEAD cipher suites (TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, and so on).


The key distribution problem

To use symmetric encryption, you must already hold the same key as the other party before communicating. The problem is how to hand that key over safely.

Diagram showing that a key sent by email is stolen along the path, that sending the password in a separate email lets the eavesdropper see both over the same path, that handing it over in person is impossible with someone on the internet, and that a separate key is needed for each partner, so 100 people need 4,950 keys
  • Send it by email: unless the email path is secure, the key is stolen along with the message
  • Send the password of an encrypted ZIP in a separate email: you only use the same path twice, so the security barely changes
  • Hand it over in person: safe, but impossible with a stranger on the internet

On top of that, a separate key is needed for each partner, so for n people to communicate with one another you need n(n−1)/2 keys, which is 4,950 keys for 100 people.

In other words, you fall into a loop: handing over a key safely already requires a secure channel. This is called the key distribution problem. The next topics, public key encryption and key exchange, solved this problem.


Public key encryption (RSA and elliptic curves)

Public key encryption uses a pair of two keys.

  • Public key: can be given to anyone
  • Private key: held only by its owner

Data encrypted with the public key can be decrypted only with the paired private key.

Diagram showing that the receiver creates a key pair and distributes the public key (which also reaches the eavesdropper), and that ciphertext made by the sender with the public key cannot be opened with the public key and can be decrypted only with the receiver's private key

As a padlock analogy, the public key is an open padlock that anyone can close, and the private key is the only key that can open it. You hand out the key that locks and never let the key that opens leave your hands. This way you do not need to hand over a decryption key, and the key distribution problem is avoided.

There are two representative methods.

  • RSA (1977): relies on the difficulty of factoring large numbers
  • Elliptic curve cryptography (ECC): relies on the difficulty of calculations on an elliptic curve (P-256, Curve25519, and so on). It gives the same strength with a much shorter key than RSA (RSA 3072-bit ≈ elliptic curve 256-bit)

However, public key encryption is orders of magnitude slower than symmetric encryption, and RSA can encrypt in one operation only data shorter than the key length (a few hundred bytes) (we try this in Part 3). So in practice it is used for handing over keys and for signatures. This is why “HTTPS encrypts data with RSA” at the beginning is wrong.


Key exchange (DH and ECDHE)

The way today’s TLS shares a symmetric key is key exchange.

Diagram showing Alice and Bob each mixing their own secret color into a shared yellow, exchanging the mixed orange and green, and adding their own secret color to the color they received so both end up with the same brown, while the eavesdropper sees only orange and green

In Diffie-Hellman (DH) key exchange (1976), each side creates a secret value and exchanges only a public value calculated from it. Combining the other side’s value with your own secret value gives the same value on both sides.

Here is the analogy with paint.

  1. Agree on a common color (yellow)
  2. Each side mixes in its own secret color (yellow + red = orange, yellow + blue = green)
  3. Exchange the mixed colors (orange and green)
  4. Mix your own secret color into the color you received, and both end up with the same brown

You cannot extract the original colors from a mixed color, so an eavesdropper cannot make the same color.

The version done on an elliptic curve is called ECDH, and the version that uses a one-time value for each connection is called ECDHE (the E stands for Ephemeral). In TLS 1.3, ECDHE such as X25519 is the standard.

However, DH does not verify the other party. To prevent the man-in-the-middle attack from Part 1, you need certificates and signatures.


Forward secrecy and TLS’s hybrid design

Up to TLS 1.2, there was also a method in which the client encrypted the key material it created with the server’s RSA public key and sent it (RSA key exchange).

Diagram showing that with RSA key exchange an attacker can record traffic and read all past traffic when the server's private key leaks years later, while with ECDHE the one-time values are discarded so recordings stay unreadable even if the private key leaks, and that today's TLS combines three things: ECDHE, a certificate and signature, and AES-GCM

With this method, if an attacker records the encrypted traffic and later gets the server’s private key, the attacker can decrypt all past traffic.

ECDHE, on the other hand, discards the per-connection secret value after use, so even if the private key leaks later, past traffic cannot be read. This property is called forward secrecy. TLS 1.3 removed RSA key exchange. The idea is not to keep a key that would hurt if it leaked in the first place.

Today’s TLS is a hybrid design that combines the following three things.

  1. Key exchange (ECDHE) creates the material for the symmetric key
  2. A certificate and signature verify that the other party is genuine
  3. From then on, the data is protected with symmetric authenticated encryption (AES-GCM and others)

Public key technology is used only at the start, and the actual data is protected with a symmetric key.

Key points
• With RSA key exchange, if the private key leaks, even recorded past traffic can be read
• ECDHE discards its one-time values, so past traffic stays protected
• TLS combines “key exchange + certificate and signature + symmetric AEAD”


Hash functions (SHA-2 and SHA-3)

A hash function calculates a fixed-length value (the hash value) from data of any length.

Diagram showing that the one-character difference between "hello world" and "hello World" gives a completely different SHA-256 hash value, together with four properties: one-way, collision resistance, a one-character change alters the value greatly, and fixed-length output

A hash function used in cryptography is required to have four properties.

  1. One-way: the original data cannot be recovered from the hash value
  2. Collision resistance: you cannot find different data that gives the same hash value
  3. A one-character difference in the original data changes the hash value completely
  4. The output length is fixed, regardless of the input length

The current standard is SHA-2 (SHA-256, SHA-384, SHA-512, and so on), and SHA-3 (2015, FIPS 202), which has a different structure, has also been standardized. Hashes are used for checking downloaded files, certificate fingerprints, preprocessing for signatures, and more.

For storing passwords, use dedicated methods that are deliberately slow to compute (PBKDF2, bcrypt, Argon2, and so on).


Why MD5 and SHA-1 cannot be used

What happens when collision resistance is broken?

YearEventMeaning
2004A collision (different data with the same hash value) is found in MD5Collision resistance was broken
2008Researchers demonstrate that MD5 collisions can be used to create a fake CA certificate that browsers trustForging certificates became real
2012The Flame malware forges a Microsoft signature using an MD5 collision and spreads disguised as Windows UpdateIt was used in a real attack
2017SHAttered: the first SHA-1 collision. Google and CWI publish two different PDFs with the same hash valueSHA-1 was also practically broken
2017Major browsers stop trusting server certificates signed with SHA-1SHA-1 disappears from public certificates
2020SHA-1 is a Shambles: a chosen-prefix collision is used to forge PGP keys (computing cost about US$45,000)Forgery with chosen content became possible
2026Under the CA/Browser Forum requirements, SHA-1 signatures on certificates and CRLs are fully retired by September 15Exit from the public PKI

If collisions can be created, you can have someone sign a harmless document and reuse that signature on a harmful document with the same hash value. MD5 and SHA-1 still work for checking accidental corruption, but for tamper protection and signatures, use SHA-256 or stronger.


MACs and digital signatures

Here is an important pitfall. Attaching a hash value alone does not prevent tampering. An attacker can rewrite the body and then recalculate and swap in the hash value as well.

Diagram showing that with only a hash value attached an attacker can recalculate and swap the value, that a MAC (HMAC) uses a shared key so an attacker without the key cannot make one but the two key holders cannot be told apart, and that a digital signature is made with a private key and anyone can verify it with the public key

So you attach a value that only a key holder can create.

  • MAC (message authentication code): the sender and the receiver hold the same shared key, and a value is calculated from the body and the key. The representative is HMAC (RFC 2104). An attacker who does not know the key cannot produce a correct value, but you cannot tell which of the two key holders made it
  • Digital signature: the sender signs the hash value of the body with their own private key, and the receiver verifies it with the public key. Only the owner of the private key can make it, so it can show the creator even to a third party

Note that “a signature is a hash encrypted with a private key” is an analogy that holds only for RSA and does not apply to ECDSA and others. “Encrypt with the public key, sign with the private key” from the beginning is the correct understanding.

Differences between a hash, a MAC, and a signature

ItemHashMAC (HMAC)Digital signature
Key usedNoneShared key (both parties hold the same key)Sign with a private key, verify with a public key
Who can create itAnyoneEveryone who has the keyOnly the owner of the private key
Who can verify itAnyoneOnly those who have the keyAnyone who has the public key
What you learnAccidental corruptionWhether it was tampered withWhether it was tampered with, and who created it
Proof to a third partyNot possibleNot possiblePossible
SpeedFastFastSlow
Main usesFile checks, fingerprintsTLS key derivation and verification, API authenticationCertificates, TLS handshakes, code signing

The difference is “who can create it” and “who can verify it.” HMAC is a MAC that uses a shared key and is a different technology from a signature, which uses public key cryptography. In TLS 1.3, signatures are used to verify the certificate and the handshake, and HMAC is used for key derivation (HKDF) and for the final handshake check (Finished).


Signature algorithms (RSA, ECDSA, Ed25519)

AlgorithmUnderlying mechanismFeaturesWhere it can be used and cautions
RSA (PKCS#1 v1.5)RSAThe oldest, with high compatibilityStill the mainstream for signing public certificates. Not used for TLS 1.3 handshake signatures (an exception for client certificates on old devices: RFC 9963)
RSA-PSSRSAA newer format that adds a random value (salt). Has a security proofSignatures when using an RSA key in TLS 1.3
ECDSAElliptic curve (P-256 and others)Small, fast keys and signatures. Needs a one-time random number for each signatureCan be used in public certificates. Reusing the random number leaks the private key
Ed25519 (EdDSA)Elliptic curve (Curve25519 family)Fast and does not depend on random numbers (deterministic). Hard to implement incorrectlySSH keys, software signing. Cannot be used for public TLS certificates
ML-DSALattice (PQC)Considered unbreakable even by quantum computers. Signatures are large, several KBFIPS 204 (2024). Use in certificates is still ahead

Under the CA/Browser Forum requirements, the keys usable in public server certificates are only RSA (2048 bits or more) and ECDSA (P-256, P-384, P-521). The sizes of signatures actually made with OpenSSL 3.5 were 384 bytes for RSA 3072-bit, about 70 bytes for ECDSA P-256, 64 bytes for Ed25519, and 3,309 bytes for ML-DSA-65.


Key length and strength

Security strengthSymmetric keys and hashesRSA and DH / elliptic curvesStatus (NIST and CRYPTREC)
80 bits or less2TDEA, SHA-1 (for signatures)RSA 1024 / 160 bitsNot allowed
112 bitsSHA-224RSA 2048 / P-224Until 2030. Avoid for anything new
128 bitsAES-128, SHA-256RSA 3072 / P-256, X25519Minimum from 2031
192 bitsAES-192, SHA-384RSA 7680 / P-384For long-term protection
256 bitsAES-256, SHA-512RSA 15360 / P-521For long-term protection

(Sources: NIST SP 800-57 Part 1 Rev.5 (2020), SP 800-131A Rev.2 (2019), the CRYPTREC Cryptographic Algorithm List (revised in March 2026, adding a PQC list that includes ML-KEM), and its “Criteria for Setting Cryptographic Strength Requirements (Algorithm and Key Length Selection)”)

  • RSA 2048 has 112-bit strength, and under the standards in the table above (CRYPTREC and NIST SP 800-131A Rev.2) it can be used for new encryption and signing only until 2030. For keys you create from now on, choose RSA 3072 or larger, or P-256 or larger
  • NIST IR 8547 became final in October 2026. It makes public-key schemes that are weak against quantum computers, such as RSA and elliptic curves (including 112-bit strength ones such as RSA 2048), deprecated after 2030 and disallowed after 2035. This schedule replaces the one planned in SP 800-57, under which 112-bit public-key schemes would be disallowed from 2031 (112-bit symmetric schemes are disallowed in 2030). SP 800-131A Rev.3 is still a draft, and items such as ending ECB are still proposals

Random numbers

The security of cryptography assumes that keys and nonces are made from unpredictable random numbers.

Diagram showing that the OS random number generator produces key pairs, ECDHE one-time values, handshake random values, per-signature ECDSA values, and nonces, with two cases: Debian's OpenSSL in 2008, where only tens of thousands of keys were possible, and a game console's ECDSA in 2010, where reusing the same value let the private key be computed

TLS also uses random numbers everywhere: for key pairs, ECDHE one-time values, and per-signature ECDSA values. If the random numbers are biased, security collapses even when the algorithm and key length are correct.

  • 2008: A mistake in a fix to Debian’s OpenSSL left the source of randomness as little more than the process ID, so only tens of thousands of possible keys could be generated
  • 2010: A game console used the same value for every ECDSA signature, so the private key could be computed from the signatures
  • There are also cases where embedded devices just after startup lacked a source of randomness and ended up with duplicate keys

For random numbers, use the OS cryptographic random number generator (getrandom() on Linux, BCryptGenRandom on Windows), and do not use rand() or PowerShell’s Get-Random.


Post-quantum cryptography (PQC)

Finally, a topic a little further ahead. Once practical quantum computers exist, it is expected that today’s public key cryptography, such as RSA, DH, and elliptic curve cryptography, will be broken. The impact on symmetric encryption and hashes is relatively small and can be handled with longer keys (such as AES-256).

Diagram showing an attack in which an attacker records traffic in 2026 and decrypts it with a future quantum computer, that moving key exchange to PQC now keeps recordings unreadable, and the migration status as of September 2026: key exchange is in use with X25519MLKEM768, signatures and certificates are still ahead, and symmetric keys and hashes are handled with longer keys

The pressing problem is the attack of recording today’s traffic and decrypting it with a future quantum computer (Harvest Now, Decrypt Later). For information that must stay secret for a long time, key exchange needs to be migrated first. Signatures can be switched in time if you switch before the day they can be broken.

  • In August 2024, NIST standardized ML-KEM (FIPS 203) for key establishment, and ML-DSA (FIPS 204) and SLH-DSA (FIPS 205) for signatures
  • In TLS, the hybrid key exchange X25519MLKEM768, which combines X25519 and ML-KEM-768, is used by major browsers and OpenSSL 3.5 and later (Part 7)
  • Migrating signatures and certificates is still ahead

Remember: key exchange is the urgent part. Recorded traffic cannot be protected afterward.


Think about it

  1. Suppose your company has a practice of “encrypting a ZIP file and sending the password in a separate email.” How far does that solve the key distribution problem?
  2. Is the explanation “We distribute the SHA-256 hash value together with the file, so we can tell if it was tampered with” correct? Think about where the hash value is obtained from.
  3. Do any of your devices or servers use an RSA 1024-bit key, a SHA-1 signature, or TLS 1.2 RSA key exchange? What do you need to replace by 2030?

Hint: The tables “Differences between a hash, a MAC, and a signature (who can create and verify),” “Forward secrecy,” and “Key length and strength” in this article are good clues.


Summary

  • The actual data is encrypted with symmetric encryption (AEAD such as AES-GCM). Do not use ECB
  • Symmetric keys have the key distribution problem. Public key encryption and key exchange solve it
  • Today’s TLS is ECDHE + certificate and signature + AEAD. ECDHE gives forward secrecy
  • A hash value alone cannot prevent tampering. Only a digital signature can also show who created it
  • Do not use MD5 or SHA-1. Choose RSA 3072 or larger, or P-256 or larger, for new keys
  • PQC migration is starting with key exchange

Next time, we run the components seen here for real with openssl and PowerShell.


Watch the video

This part is also explained in a YouTube video (about 21 min).

All parts of the series are in the Certificate Fundamentals playlist on YouTube.

The Certificate Fundamentals series (11 parts)

All 11 parts with a reading guide: Certificate Fundamentals

  1. Why Do We Need Certificates?
  2. Cryptography basics (this article)
  3. Trying it with openssl and PowerShell
  4. Inside an X.509 certificate
  5. PKI and how trust works
  6. Certificate types and issuance
  7. How TLS works
  8. Lifecycle and automation
  9. Private PKI and the cloud
  10. Certificate troubleshooting
  11. Certificate design exercises

This series is the English edition of 【証明書入門】, originally written in Japanese.

コメント

Copied title and URL