Public Key
Definition
Public keys are the shareable halves of asymmetric key pairs, published in certificates so others can verify signatures made with the matching private key.
A public key is the half of an asymmetric key pair that can be shared freely. In an X.509 certificate it sits in the SubjectPublicKeyInfo (SPKI) field together with its algorithm, for example RSA, ECDSA on the P-256 curve, or Ed25519. The certificate exists to bind that public key to a name: the CA's digital signature over the certificate asserts that the key belongs to example.com. Anyone can use it to verify signatures made with the matching private key, and with RSA it can also encrypt data that only the private key can decrypt.
Why it matters
Clients use the server's public key to check the signature in the TLS handshake, which is how they know they are talking to the key holder and not an impostor. Hashes of the SPKI are used for certificate pinning, DANE TLSA records and for checking that a key, CSR and certificate belong together. If a renewal keeps the same key pair, the SPKI hash stays the same even though the certificate changes, which is why pinning and key rotation must be planned together.
Example
openssl x509 -in example.com.crt -noout -pubkey > example.com.pub.pem
openssl pkey -pubin -in example.com.pub.pem -noout -text | head -1
# Public-Key: (256 bit)
Common misconceptions
- The public key should be kept secret. It is public by design; only the private key needs protection.
- TLS encrypts traffic with the server's public key. In TLS 1.3 the certificate key only signs; traffic keys come from an ephemeral (EC)DHE exchange.
- A public key and a certificate are the same thing. The certificate wraps the public key with identity information, validity dates and the CA's signature.