Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Secrets and key pairs

A credential is the value that lets a person or an application prove a claim about an account. Shared secrets and key pairs both do that job, but they differ in one way that matters most: whether the party checking the proof could also make one.

What a credential is

When Ava signs in to the photo service, her password proves the account is hers. The printer, the application she connected to her photos, has the same problem in its own form. When it asks the photo service's authorization server for an access token, it identifies itself with its client ID and proves the claim with a client secret. And when it sends a finished photo book to the print lab, the business that prints the books, the print lab's API needs to know that each order really comes from the printer.

In this series, a credential is the secret or key that a person or application uses to prove that an account or relationship belongs to it. Ava might use a password or a passkey. The printer might use a client secret or a private key.

The word is used in more than one way, so it helps to know the others. NIST's digital identity guidelines call the secret or device itself an authenticator, and reserve "credential" for the record that binds an authenticator to one account. A verifiable credential is something else again: a set of claims about a person, signed by whoever issued them. The ideas in this lesson apply under any of these names.

A credential is different from an identifier. Ava's email address says which account is being claimed; the password supports the claim. The printer's client ID says which client is calling; the client secret is what the authorization server checks. Identifiers can be known by many people. A credential is only useful as evidence if its holder can keep it from others.

Shared secrets

With a shared secret, the holder and the verifier both rely on the same secret value. A password is the familiar example, though a careful verifier stores only a salted, deliberately slow hash of it, as Protecting credentials and messages described. An API key or client secret is another. Suppose the print lab issues the printer a long random API key, and the printer sends it with each order.

Sending the secret itself means anyone who captures one request, or finds the value in a log, can use it. A better use of a shared secret is to prove knowledge of it without sending it. With a keyed hash such as HMAC, from Encoding and hashing, the printer combines the key with the order's content to produce a short tag. The print lab, which holds the same key, calculates the tag again and compares. The key never travels with the order.

A shared key has a built-in limitation, however. Because the print lab can calculate the tag, it could also create one. Anyone who steals the print lab's copy of the key can send orders that look exactly like the printer's, for albums the printer never asked to print. Whenever a verifier needs the secret itself to do its check, its copy can create proofs as well as check them, so each relationship needs its own secret and every copy needs the same protection. A verifier that receives the secret itself, such as a password or an API key, can store only a hash of it instead, but then the secret travels with every request.

A shared secret is only as strong as it is hard to guess, and "hard to guess" has a precise meaning: it must come from a cryptographically secure random number generator, the kind an operating system provides for exactly this purpose, and that openssl rand uses. The everyday random functions in many programming languages are built to look varied, not to resist prediction, and someone who sees a few of their outputs can often work out the next. A secret needs enough randomness, too. A 256-bit value, written as 64 hexadecimal characters, has so many possibilities that guessing it is hopeless, while a six-digit number can be tried exhaustively in seconds unless the verifier limits attempts. The same rule applies to every value an attacker must not predict: session identifiers, one-time challenges, and the random values attached to sign-in requests.

Key pairs

Public-key cryptography splits that capability in two. A key pair is a private key and a public key generated together and mathematically related. The private key can create a signature. The public key can check that signature but cannot create one, and the private key cannot practically be worked out from it.

The printer keeps its private key to itself and gives the print lab the public key. Now the print lab can check that an order was signed by the printer, but a thief who steals the print lab's copy of the public key gains nothing they could not already find. The same public key can be given to any number of verifiers without adding risk.

HMAC tag on each order

The printer proves with
The shared key
The print lab checks with
The same shared key
A thief copies the print lab key
Can make new tags

Forged orders look genuine

Signature on each order

The printer proves with
The printer's private key
The print lab checks with
The printer's public key
A thief copies the print lab key
Can only check signatures

Forged orders are refused

Whenever a verifier needs the secret itself to do its check, its copy can create proofs as well as check them.

A stolen copy of the verifier's key lets a thief forge HMAC tags, but not signatures.

In code, the difference is which key each side holds. In the illustration below, constant_time_equal compares the two tags in the same amount of time however many characters match, so the time a refusal takes doesn't tell an attacker how close a guessed tag came.

# Shared key: both sides can create and check the same tag
# Printer
tag = hmac_sha256(shared_key, order)
# Print lab
accepted = constant_time_equal(received_tag, hmac_sha256(shared_key, received_order))

# Key pair: only the private key can sign
# Printer
signature = sign(printer_private_key, order)
# Print lab
accepted = verify(printer_public_key, received_order, received_signature)

Two families of key pair are in wide use. RSA keys are built from very large numbers, a few thousand bits long. Elliptic curve keys are built on a named mathematical curve, most often P-256, and reach the same strength with much shorter keys and faster signing. The algorithm names from Keys, encryption, and signatures say which family they use: RS256 signs with an RSA key, and ES256 signs with ECDSA, the elliptic curve signature algorithm, on a P-256 key. Both hash the data with SHA-256 first.

Key pairs can also protect confidentiality: data encrypted with a public key can be decrypted only with the matching private key. In practice, public-key operations are much slower than shared-key ones, so protocols such as TLS use key pairs to authenticate and agree on fresh shared keys, then use those shared keys to protect the rest of the connection.

If Ava signs in to the photo service with a passkey, that is a key pair too. The photo service stores only the public key, so a breach of its database reveals nothing that could sign in as Ava.

Shared secrets compared with key pairs
QuestionShared secretKey pair
Who can create a valid proof?Everyone holding the secret, including the verifierOnly the private key holder
What does the verifier store?The secret, or a hash when the holder sends the secret itself, as with a passwordThe public key, which is not secret
What if the verifier's copy leaks?The attacker may be able to impersonate the holderThe attacker can verify signatures, nothing more
How many verifiers can share it?Ideally one per secretAny number

Proving possession

A signature over a fixed message has a weakness: if an attacker records it, they can send the same signed message again. To show that the key holder is present now, a verifier can issue a challenge, a random value it has never used before. The holder signs the challenge, and the verifier checks the signature with the public key. Because each challenge is fresh, an old answer is useless.

That is the core of passkey sign-in, and of how a TLS server proves it holds the private key for its certificate: the Certificate Verify signature in the handshake from HTTPS and certificates in practice covers the handshake so far, including random values both sides chose for that connection. The key itself never leaves its holder.

Many credentials work differently. A bearer credential, such as an API key sent with each request or an ordinary access token, is accepted from whoever presents it. Proof-of-possession designs bind a credential to a key, as Protecting credentials and messages described, so the client must answer for that key each time and a copied token is not enough on its own.

Whose key is it?

A public key on its own is just a long number. Before trusting a signature, the print lab needs to know that this public key belongs to the printer, not to someone who sent the print lab their own key while claiming to be the printer. A valid signature checked against the wrong key proves only that the wrong party signed.

For a small number of partners, the answer can come from setup: the printer hands the print lab its public key through a channel the print lab already trusts, and the print lab records it against the printer's registration. At the scale of the web, where a browser meets millions of servers it has never seen, that does not work. There the binding comes from a certificate: a signed document, issued by an authority the browser already trusts, that ties a public key to a name.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The printer asks the authorization server for a token with its client ID and its client secret. Which one is the credential? 1 of 3

Choose one answer.

An attacker steals the print lab's copy of the key it uses to check the printer's orders. When does that let the attacker create orders the print lab will accept? 2 of 3

Choose one answer.

Someone recorded the printer's signed answer to yesterday's challenge and sends it again today. When does the print lab refuse it? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity