How HTTPS Works: RSA, ECDSA, ECDHE and AES-GCM Together in TLS 1.2 and TLS 1.3

17 Min Read • Published on Nov 25, 2026
Tutorial contents
In this page

When you open an HTTPS page, three different kinds of cryptography work together in the first few milliseconds. Almost every beginner confusion about TLS comes from thinking one algorithm does all three jobs. It does not. This page separates the jobs, then shows each one in a real captured handshake.

JobThe question it answersWho does itLasts
1. Authenticate“Am I really talking to www.example.com?”The server’s signature (ECDSA or RSA), plus its certificateOne signature per connection
2. Agree on a secret“How do we share a secret without ever sending it?”ECDHE key agreementOne new secret per connection
3. Encrypt the data“How do we hide and protect the web page?”AES-GCM or ChaCha20-Poly1305, with keys made by a KDF (HKDF / PRF)The whole connection

Two analogies carry the whole page:

  • The server’s permanent key (RSA or ECDSA) is like a passport and a signature. It is long-lived, it proves who you are, and it is never used to carry the shipment.
  • The session keys (AES) are like a combination lock that you and the server set together on the spot, use for this one delivery, and then throw away.

1. Why the permanent key does not encrypt your traffic

RSA and ECDSA keys last for months or years. They sit in a certificate that anyone can download. If they encrypted the traffic, there would be two problems:

  • They are slow. On the lab machine from the cryptography page, an RSA-2048 private-key operation ran about 1,800 times a second. AES-256-GCM processed about 6.7 gigabytes per second on the same laptop (openssl speed -evp aes-256-gcm). Encrypting a video stream with RSA would be hopeless.
  • They have size limits. RSA-2048 can only encrypt about 190 bytes at a time. A web page is thousands of times bigger.

There is a third, more important reason, which is forward secrecy. If the permanent key encrypted the traffic, anybody who recorded your traffic today and stole the key next year could read all of it. Throw-away session keys avoid that (more on this in section 4).

And for ECDSA there is an even simpler reason: ECDSA cannot encrypt at all. It can only create and verify signatures. You can’t “lock” anything with it.

So the split is:

Permanent keys (RSA, ECDSA)Session keys (AES-GCM, ChaCha20)
CreatedOnce, long ago, by the server’s adminOn the fly, for each connection
LivesMonths in a certificateUntil the connection closes
JobProve identity (sign)Encrypt every byte of HTTP
SpeedSlow, so used a few times per connectionVery fast, so used for everything
Where it comes fromA key generatorDerived from an ECDHE secret

2. The lab: one server, three kinds of connection

We will make two throw-away certificates, one with an ECDSA key and one with an RSA key, and connect to them in different modes. These are self-signed, so the client is told to trust each one directly with -CAfile.

$ openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
    -keyout ecdsa-site.key -out ecdsa-site.crt -days 30 \
    -subj "/CN=ec.example.test" -addext "subjectAltName=DNS:ec.example.test"
$ openssl req -x509 -newkey rsa:2048 -nodes \
    -keyout rsa-site.key -out rsa-site.crt -days 30 \
    -subj "/CN=rsa.example.test" -addext "subjectAltName=DNS:rsa.example.test"

Start a test server for each (the RSA one is told to allow old cipher suites, because later we want to show a legacy connection):

$ openssl s_server -accept 15443 -cert ecdsa-site.crt -key ecdsa-site.key -www -quiet &
$ openssl s_server -accept 15444 -cert rsa-site.crt -key rsa-site.key -www -quiet \
    -cipher 'ALL:@SECLEVEL=0' &
Reading the output
openssl s_client -trace prints every handshake message. We pick out only the interesting lines. If you try this yourself, the byte lengths can differ by a few bytes between runs (signatures vary in size), but the sequence of messages will not.

3. How ECDSA works in TLS: it signs, and that is all

Connect to the ECDSA server with TLS 1.3. We force the plain X25519 key exchange, because OpenSSL 4.1 would otherwise use a larger post-quantum hybrid group and make the output harder to read:

$ openssl s_client -connect localhost:15443 -tls1_3 -groups X25519 \
    -CAfile ecdsa-site.crt -trace </dev/null 2>&1 | grep -E "Hello, Length|Certificate, Length|CertificateVerify|Finished|Peer signature|Cipher is"
    ClientHello, Length=226
    ServerHello, Length=118
    Certificate, Length=400
    CertificateVerify, Length=75
    Finished, Length=48
    Finished, Length=48
Peer signature type: ecdsa_secp256r1_sha256
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384

Look at the sequence. The server sends its Certificate (the public key and name, signed by a CA) and right after it a message called CertificateVerify. That second message is where ECDSA does its entire job:

  1. The server takes a hash of everything said in the handshake so far: the client’s hello, its own hello, including the ECDHE public value it just sent (the key_share), and its certificate.
  2. It signs that hash with its ECDSA private key.
  3. The client checks the signature with the public key in the certificate.

What does a good signature prove?

  • The server holds the private key. A certificate is public, so anyone can present it. Only the real owner of the key can sign.
  • The key exchange is authentic. Because the ECDHE value was inside the signed data, the client knows the value really came from this server and was not swapped by someone in the middle. (Without this, an attacker could run key agreement with the client and with the server separately and read everything. This is the “man-in-the-middle” attack, and the signature is what stops it.)
  • It is fresh. The signed data contains random values from this very connection, so an old recording of someone else’s signature cannot be replayed.

Think of the server writing “I, www.example.com, am agreeing this lock with the person who sent this hello” on a note and signing it with their personal seal. The client compares the seal with the picture on the passport (certificate).

After the handshake finishes, ECDSA plays no role at all. The private key is never used again for this connection. Not one byte of the page is signed or encrypted with ECDSA. It checked the passport once, at the door.

TLS 1.2 calls it something else
The message CertificateVerify belongs to TLS 1.3. In TLS 1.2 the server produces the same kind of signature, but it is carried inside the ServerKeyExchange message (you will see it below). In TLS 1.2 a message named CertificateVerify exists too, but it is for the client’s certificate in mutual TLS. Same idea, different name and different place.

4. Key exchange: ECDHE makes the secret, nobody sends it

Neither RSA nor ECDSA creates the session keys. A different mechanism does: ECDHE (Elliptic Curve Diffie-Hellman, Ephemeral). You met the idea of mixing paint on the cryptography page. In TLS:

  1. The client makes a fresh, temporary key pair and sends its public half in the ClientHello (key_share).
  2. The server does the same and sends its public half in the ServerHello.
  3. Each side combines its own private half with the other’s public half. The maths guarantees both get the same secret number.
  4. The private halves are thrown away after the handshake. (“Ephemeral” means short-lived.)

The secret is never transmitted. An eavesdropper sees only the two public halves, and cannot compute the secret from them. Here is the same calculation with two X25519 keys:

$ openssl genpkey -algorithm X25519 -out a.key
$ openssl genpkey -algorithm X25519 -out b.key
$ openssl pkey -in a.key -pubout -out a.pub
$ openssl pkey -in b.key -pubout -out b.pub
$ openssl pkeyutl -derive -inkey a.key -peerkey b.pub | xxd -p -c 64
3252108be4d3cde4d444050f13d205850d014a884f8eec8e20be2c6bd04c7323
$ openssl pkeyutl -derive -inkey b.key -peerkey a.pub | xxd -p -c 64
3252108be4d3cde4d444050f13d205850d014a884f8eec8e20be2c6bd04c7323

Alice used her private key and Bob’s public key; Bob used the reverse. Both got the identical 32 bytes. That value is the shared secret (also called the raw or premaster secret).

Now see what really goes over the wire in TLS 1.2 with ECDHE-RSA (the server is the RSA one on port 15444):

$ openssl s_client -connect localhost:15444 -tls1_2 -cipher ECDHE-RSA-AES128-GCM-SHA256 \
    -groups X25519 -CAfile rsa-site.crt -trace </dev/null 2>&1 | grep -A6 -E "ServerKeyExchange|ClientKeyExchange"
    ServerKeyExchange, Length=296
      KeyExchangeAlgorithm=ECDHE
        named_curve: ecdh_x25519 (29)
        point (len=32): 5F2705FB0F21E12CE569332D249A0074D619B9EDF32B7EC058019BAAA979425F
      Signature Algorithm: rsa_pss_rsae_sha256 (0x0804)
      Signature (len=256): 3470705B688DB7E5E644193582B5E5108941B9FF7AE3221FEEF3F9A608C02A1D...
    ...
    ClientKeyExchange, Length=33
      KeyExchangeAlgorithm=ECDHE
        ecdh_Yc (len=32): 38F0C8A535D3B426E2B0854D006112E7403B57BEF6B8236A5B368CCF88663C0A

Read it closely, because it shows all the roles at once:

  • The server’s ECDHE public value (point, 32 bytes) is sent in the clear.
  • Straight after it comes the server’s signature (Signature, 256 bytes, the size of an RSA-2048 signature) over that value and the two hello messages. This is the “authenticates the key exchange” step. It is the RSA key signing, not encrypting.
  • The client replies with its own public value (ecdh_Yc, 32 bytes). There is no secret in that message. It is just the client’s public half.

Nothing in the capture contains the shared secret, or any key. That is the point.

Why this gives forward secrecy

The ECDHE keys are new for every connection and deleted afterwards. Suppose a spy records your connection for a year, and then steals the server’s permanent RSA or ECDSA private key. The spy can now forge the server’s signature in the future, but the old recordings are still locked: the signature key never protected the secret, and the ephemeral keys that did are gone. This property is called forward secrecy (or perfect forward secrecy). It is the main reason modern TLS looks the way it does.

5. From the secret to the real keys: the KDF

The raw shared secret is not used directly as an AES key. It is the starting material for a Key Derivation Function (KDF). A KDF takes the secret (plus context such as the hash of the handshake) and stretches and separates it into as many independent keys as needed: a key for the client to server direction, another for the reverse direction, plus the initialisation values (“IVs”).

  • TLS 1.3 uses HKDF (an HMAC-based KDF, from the HMAC section). It runs in two stages: extract (mix the secret into one strong key) and expand (produce labelled keys). It runs this in steps, so the handshake messages themselves get protected by their own keys before the application keys exist.
  • TLS 1.2 uses a PRF (pseudo-random function), also built from HMAC. It first makes a 48-byte master secret from the premaster secret and the two hello randoms, then expands the master secret into a “key block” holding the keys and IVs.

Here is a simplified version of the HKDF step, using the shared secret from above. (The real TLS 1.3 key schedule has more stages and fixed label strings; this shows the principle: one secret in, several unrelated keys out.)

$ SS=$(openssl pkeyutl -derive -inkey a.key -peerkey b.pub | xxd -p -c 64)
$ openssl kdf -keylen 16 -kdfopt digest:SHA256 -kdfopt hexkey:$SS -kdfopt hexsalt:00 \
    -kdfopt hexinfo:$(printf 'client write key' | xxd -p) HKDF
AC:73:20:57:0E:F8:6F:7F:4B:3B:35:5A:9B:6B:EE:D2
$ openssl kdf -keylen 12 -kdfopt digest:SHA256 -kdfopt hexkey:$SS -kdfopt hexsalt:00 \
    -kdfopt hexinfo:$(printf 'client write iv' | xxd -p) HKDF
15:A0:68:C6:71:26:20:5E:C0:8D:70:89

The first output is a 16-byte (128-bit) AES key; the second is a 12-byte IV for GCM. Both sides run exactly the same calculation, so both end up with the same keys without anything but public values ever crossing the network. Change the label (info) and you get a completely unrelated key, which is how one secret becomes separate keys for each direction.

6. Bulk encryption: AES-GCM (or ChaCha20) does all the work

Now every byte of HTTP is protected by the session keys:

$ openssl s_client -connect localhost:15443 -tls1_3 -CAfile ecdsa-site.crt </dev/null 2>&1 | grep -E "Protocol|Cipher is"
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Protocol: TLSv1.3

Break that name down: AES_256_GCM is the bulk cipher, and SHA384 is the hash used by the KDF. Notice what the name doesn’t contain: no RSA, no ECDSA. In TLS 1.3 the key-exchange and signature choices are negotiated separately from the cipher suite.

  • AES-GCM is an authenticated cipher: it hides the data and detects tampering, using the session key. (Why that matters is explained on the cryptography page.)
  • ChaCha20-Poly1305 is the alternative, popular on phones without AES hardware. It does the same job. openssl ciphers -s -tls1_3 lists all three TLS 1.3 suites: TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256 and TLS_AES_128_GCM_SHA256.

Because of that authentication, a network attacker who flips a bit in a packet cannot go unnoticed: the receiver will reject it.

7. RSA in modern TLS: the same job as ECDSA

If RSA does not encrypt anything in modern TLS, what is it doing? Exactly what ECDSA does: signing. The only difference is the type of key.

$ openssl s_client -connect localhost:15444 -tls1_3 -groups X25519 -CAfile rsa-site.crt </dev/null 2>&1 | grep -E "Peer signature|Peer Temp Key|Cipher is"
Peer signature type: rsa_pss_rsae_sha256
Peer Temp Key: X25519, 253 bits
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384

Compare to the ECDSA connection: the cipher suite is identical (TLS_AES_256_GCM_SHA384), the key exchange is identical (ECDHE), and only the signature line changes, from ecdsa_secp256r1_sha256 to rsa_pss_rsae_sha256. (TLS 1.3 signs with RSA-PSS, the safer padding.)

The same holds for TLS 1.2 with ECDHE-RSA suites, which you saw above: RSA signs the ServerKeyExchange, and ECDHE makes the secret. The name tells you the roles, reading left to right: ECDHE (key agreement) - RSA (signature) - AES128-GCM (bulk) - SHA256 (hash/KDF).

8. Legacy RSA (TLS 1.2 TLS_RSA_...): where RSA does encrypt

Old TLS 1.2 cipher suites named TLS_RSA_WITH_AES_128_GCM_SHA256 (OpenSSL calls it AES128-GCM-SHA256) work completely differently. There is no ECDHE and no ServerKeyExchange. RSA does the key transport:

  1. The browser makes a random 48-byte Pre-Master Secret (2 bytes of version and 46 random bytes).
  2. It encrypts the Pre-Master Secret with the server’s RSA public key (the one in the certificate).
  3. Only the server’s RSA private key can open it. Both sides then feed the pre-master secret into the PRF to make the master secret and session keys, and use AES-GCM from then on.

In everyday terms: the browser writes the combination of the lock on a note, seals it in an envelope addressed only to the server, and posts it. Anyone can record the envelope; only the server holds the key that opens it.

Capture it (the same RSA server, forcing the legacy suite):

$ openssl s_client -connect localhost:15444 -tls1_2 -cipher 'AES128-GCM-SHA256:@SECLEVEL=0' \
    -CAfile rsa-site.crt -trace </dev/null 2>&1 | grep -E "Hello, Length|Certificate,|ServerKeyExchange|ServerHelloDone|ClientKeyExchange|KeyExchangeAlgorithm|EncryptedPreMaster"
    ClientHello, Length=112
    ServerHello, Length=53
    Certificate, Length=797
    ServerHelloDone, Length=0
    ClientKeyExchange, Length=258
      KeyExchangeAlgorithm=rsa
        EncryptedPreMasterSecret (len=256): 7114D0CEBA2054347A6126DB33426F58DA69116A6950CCBFDDA57DC4666A1098E7FC...

Compare it with the ECDHE-RSA capture: there is no ServerKeyExchange at all, and the ClientKeyExchange is now 258 bytes, holding a 256-byte EncryptedPreMasterSecret. That blob is the 48-byte secret, encrypted with RSA-2048 (the output is always as long as the key). The secret really does travel across the network, just locked.

Why TLS 1.3 removed it

  1. No forward secrecy. This is the fatal flaw. The same permanent RSA key that proves the server’s identity also protects the secret of every past connection. A spy who records traffic for years, then steals or legally compels the RSA private key, can unlock every recorded envelope, recover every pre-master secret and decrypt everything. With ECDHE, the permanent key never touches the secret, so there is nothing to unlock.
  2. A reusable decryption oracle. The server must decrypt whatever a client sends and react to bad padding. Since 1998 (“Bleichenbacher”) researchers have repeatedly found ways to use those reactions to decrypt recorded sessions or forge signatures, again and again (the “ROBOT” attack in 2017). Doing RSA decryption on attacker-chosen input is a hard thing to do safely.
  3. No benefit left. ECDHE is fast and gives forward secrecy, so there was no reason to keep the old way.

TLS 1.3 therefore only allows (EC)DHE key exchange. RSA is still allowed in TLS 1.3, but only to sign (the rsa_pss_rsae_sha256 you saw earlier), never to encrypt a secret. When you see TLS_RSA_... suites in a scan report, treat them as a finding.

9. The full lifecycle, side by side

StepModern ECDSA (TLS 1.3, or TLS 1.2 ECDHE-ECDSA)Modern RSA (TLS 1.3, or TLS 1.2 ECDHE-RSA)Legacy RSA (TLS 1.2 TLS_RSA_...)
1. HelloClient and server exchange random values and agree on a cipher suiteSameSame
2. Key agreementBoth send ECDHE public values. Each computes the same shared secret locally. Nothing secret is sentSameNo key agreement. The client invents a 48-byte Pre-Master Secret
3. Server proof of identityServer sends its certificate and signs the handshake (including the ECDHE value) with its ECDSA private key (CertificateVerify in 1.3, ServerKeyExchange in 1.2)Same, but signed with the RSA private key (RSA-PSS in 1.3)Server sends its certificate. It proves itself only by being able to decrypt the pre-master secret
4. How the secret reaches the other sideNever transmittedNever transmittedEncrypted with the server’s RSA public key and sent (EncryptedPreMasterSecret, 256 bytes)
5. Turn the secret into keysHKDF (1.3) or PRF (1.2) derives the AES-GCM keys and IVsSamePRF derives a master secret, then the AES-GCM keys and IVs
6. Encrypting the pageAES-GCM (or ChaCha20) with the session keysSameSame
7. Role of the permanent key afterwardsNone. It is not used againNoneNone for data, but it is the master key to the past: whoever gets it can decrypt recorded connections
8. Forward secrecyYes: ephemeral keys are deletedYesNo
9. If the server’s private key is stolen laterAttacker can impersonate the server from now on. Old recordings stay unreadableSameEvery recorded connection can be decrypted
10. Allowed in TLS 1.3?YesYes (signing only)No, removed

10. The whole handshake, message by message

The real message order from the captures above. In TLS 1.3 everything after the ServerHello is already encrypted, so the server’s certificate is hidden from passive observers. (OpenSSL’s trace shows them decrypted because the client has the keys.)

TLS 1.3 (1 round trip)

Client                                          Server
  ClientHello  (+ ECDHE public value) ------->
                                        <------- ServerHello (+ ECDHE public value)
                                                 {EncryptedExtensions}
                                                 {Certificate}
                                                 {CertificateVerify}   <- the signature
                                        <------- {Finished}
  {Finished}                            ------->
  [HTTP data, encrypted with AES-GCM] <------>  [HTTP data]
         { } = encrypted with handshake keys

TLS 1.2 ECDHE-RSA (2 round trips)

Client                                          Server
  ClientHello  ------------------------------>
                                        <------- ServerHello
                                        <------- Certificate
                                        <------- ServerKeyExchange (ECDHE value + SIGNATURE)
                                        <------- ServerHelloDone
  ClientKeyExchange (ECDHE value) ----------->
  ChangeCipherSpec, Finished ---------------->
                                        <------- ChangeCipherSpec, Finished
  [HTTP data, encrypted] <------------------>  [HTTP data]

TLS 1.2 legacy RSA

  ClientHello  ------------------------------>
                                        <------- ServerHello, Certificate, ServerHelloDone
  ClientKeyExchange (ENCRYPTED PRE-MASTER SECRET) ->    <- no ServerKeyExchange
  ChangeCipherSpec, Finished ---------------->
                                        <------- ChangeCipherSpec, Finished

Notice two things: TLS 1.3 saves a whole round trip, so connections start faster, and the legacy flow is the only one without the server’s signed key exchange.

11. Check your own servers

$ openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null 2>&1 \
    | grep -E "Protocol|Cipher is|Peer signature|Temp Key"

What to look for:

You seeIt means
TLSv1.3Modern. Every normal handshake uses ECDHE, so it has forward secrecy
ECDHE-... in a TLS 1.2 cipher nameForward secrecy, fine
A TLS 1.2 cipher with no ECDHE/DHE (e.g. AES128-GCM-SHA256)Legacy RSA key transport. No forward secrecy. Disable it
Peer signature type: ecdsa_secp256r1_sha256The server’s key is ECDSA P-256
Peer signature type: rsa_pss_rsae_sha256The server’s key is RSA
Peer Temp Key: X25519, 253 bits (older OpenSSL versions print Server Temp Key)The curve used for the temporary ECDHE key. It is absent for legacy RSA key transport, because there is no ephemeral key

To prove a server rejects the legacy suite, ask for it and watch it fail:

$ openssl s_client -connect www.example.com:443 -tls1_2 -cipher 'AES128-GCM-SHA256' </dev/null

A handshake failure is the result you want here.

Common confusions

The mythThe truth
“RSA encrypts the web traffic”The traffic is encrypted by AES-GCM/ChaCha20 with a temporary key. RSA (when used) only signs, or in legacy TLS 1.2 encrypts a small secret
“ECDSA encrypts”ECDSA cannot encrypt. It only signs and verifies
“RSA or ECDSA makes the AES key”Neither does. ECDHE agrees a shared secret, and a KDF (HKDF/PRF) turns it into keys
“The key exchange is secret because it is encrypted”The public values are sent in the clear. It is secure because the secret cannot be computed from them
“The certificate proves the server is real”The certificate is public. The signature made with its private key proves the server holds it
“A longer RSA key adds forward secrecy”Forward secrecy comes from using ephemeral key exchange, not from key length
“TLS 1.3 dropped RSA”It dropped RSA key transport. RSA signatures and RSA certificates still work

Recap

  1. The server’s permanent key (ECDSA or RSA) only signs. It proves identity and authenticates the key exchange, once per connection.
  2. ECDHE makes a fresh shared secret on each connection without sending it.
  3. A KDF (HKDF in TLS 1.3, PRF in TLS 1.2) turns that secret into the AES-GCM keys.
  4. AES-GCM (or ChaCha20-Poly1305) encrypts every byte of the data.
  5. After the handshake, the permanent key plays no part.
  6. In legacy RSA suites the permanent key also protects the secret, which is why a later key theft exposes the past, and why TLS 1.3 removed it.

Next, certificates and PKI explains the other half of step 1: how the client knows the public key really belongs to that server.


About BastionXP

BastionXP is a cloud-native private PKI CA and device identity management platform that eliminates passwords and shared secrets by issuing hardware-attested certificates to mobile devices and laptops. Secure access to your Wi-Fi, VPN, and SaaS applications in your enterprise network. Replace legacy SCEP with automated ACME Device Attestation. No shared secrets. Zero credential theft. Learn more about BastionXP →

Start Your Free Trial Now

Try BastionXP for free with no commitments. No credit card required.