Digital signatures
A digital signature lets anyone holding a public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt. check that a message came from the matching private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner. and has not changed, however many systems it passed through. What it cannot do is decide whether the message suits this reader, now.
A token worth checking
When Ava connects the printer to her photos, the photo service's authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. issues the printer an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in.. The printer stores it, and later sends it with each request to the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests.. Each connection along the way may use HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest., but HTTPS only protects data while it moves between two endpoints. On the last hop it protects the tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. from the printer to the API. It says nothing about whether the printer, or anyone who broke into the printer's storage, changed the token after the authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. server issued it.
The photo API wants assurance that travels with the token itself: that it came from the authorization server, and that nobody changed a value on the way. A digital signature provides that. The authorization server signs the token with its private key, and anyone holding the matching public key can check it, no matter how many systems the token passed through.
Signing and verifying
Signing starts with a hashTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash.. As Encoding and hashing showed, a cryptographic hash function such as SHA-256 turns any amount of data into a short, fixed-size digest, and changing even one character of the input changes the digest completely. The digest acts as a compact fingerprint of the exact bytes being signed.
The authorization server calculates the hash of the token's signed part and uses its private key to produce a signature over it. Most signature algorithms work this way; EdDSA takes the message itself and does its hashing inside the algorithm, mixed with key material, but the idea is the same. It sends the token and the signature together. The photo API calculates the hash of what it received, then uses the public key to check that the signature matches that hash. Widely used signature algorithms include ECDSA, EdDSA (often as Ed25519), and RSA. The example later in this lesson uses ES256, ECDSA on a P-256 key with SHA-256, from Secrets and key pairs.
If anyone changes a value in the token, the API's hash no longer matches the one that was signed and verification fails. They cannot produce a new matching signature without the authorization server's private key.
A signature covers exact bytes, not meaning. If a gateway decodes the token's payload and encodes it again with different spacing, or with its fields in a different order, the hash changes and the signature fails even though the content means the same thing. Signed formats deal with this by signing a fixed encoding. A JSON Web TokenA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. signed as a JSON Web SignatureThe JOSE format for signed content, defined in RFC 7515. A signed JWT is a JWS: a header, a payload and a signature, each base64url-encoded and joined by dots. (JWS), for example, signs its encoded header and payload exactly as they appear in the token, the base64urlA way of encoding data as ordinary text characters so it can travel safely in headers, URLs, and JSON. Anyone can decode it, so it hides nothing; Base64url is a variant safe for URLs, used in JWTs. text before the second dot, and the verifier checks those same characters.
As the authorization server signed it
- Signed bytes
- Unchanged
- Signature check
- Passes
- Claims check
- Passes
Accept
aud edited after signing
- Signed bytes
- One value changed
- Signature check
- Fails
- Claims check
- Not reached
Reject
Same meaning, different spacing
- Signed bytes
- Spacing changed
- Signature check
- Fails
- Claims check
- Not reached
Reject
Checked by another reader
- Signed bytes
- Unchanged
- Signature check
- Passes
- Claims check
- Fails: aud names another reader
Reject
A signature covers exact bytes, not meaning.
What a signature shows
A signature that verifies shows two things: the content has not changed since it was signed, and it was signed with the private key matching the public key the photo API used. Everything else needs another source of confidence.
It does not show who holds that private key. If the API was given the wrong public key, a valid signature proves only that the wrong party signed. It does not show that the content is true; an authorization server with a bug can sign a mistaken claim. It does not keep the content secret either. As Protecting credentials and messages explains, a signed JSON Web Token can usually be decoded and read by anyone who has it.
A signature also does not say that a message is recent or intended for its reader. Someone who recorded a signed token can present it again later, or to a different recipient, and the signature will still verify.
Deciding what to accept
To close those gaps, the authorization server includes the facts the photo API needs inside the signed content. Here is a fictional signed access token for Ava, shown decoded so the fields are readable:
Header
{
"alg": "ES256",
"kid": "photos-2026-10",
"typ": "at+jwt"
}
Payload
{
"iss": "https://auth.photos.example",
"aud": "https://api.photos.example",
"sub": "user-3117",
"scope": "photos.read",
"iat": 1792800000,
"exp": 1792803600,
"jti": "at-5c81e2"
}The issuer (iss) names the authorization server, and the audience (aud) names the photo API as the intended recipient. The issued-at (iat) and expiry (exp) times, in Unix seconds, bound when the token is acceptable, and the unique identifier (jti) lets a recipient notice a token it has already seen when that matters. The type (typ) at+jwt marks it as an access token, so it cannot be mistaken for another kind of signed statement from the same key. Because these fields are covered by the signature, nobody can change them without verification failing.
The header also carries an algorithm name and a key ID, which the API treats as hints for choosing among the issuers, keys and algorithms it already trusts, never as instructions:
key = trusted_issuer_keys.find(header.kid) # from the API's own configuration
if key is None or header.alg not in key.allowed_algorithms:
reject()
if not verify(key, signed_bytes, signature):
reject()
if header.typ != "at+jwt":
reject()
if payload.iss != PHOTOS_ISSUER or payload.aud != PHOTO_API:
reject()
if now() > payload.exp:
reject()
accept(payload)Where signatures appear
Once you know the pattern, signatures appear throughout identity systems. The passport chip from Proofing methods carries data signed by the issuing authority. A passkey signs a challenge during sign-in. Identity providers sign the assertions and ID tokens that tell an application who signed in, and the certificates from HTTPS and certificates in practice are themselves signed statements.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Compare readable claims with a checked signatureSign Ava in, verify her signed access token, then rebuild it with one value changed and with reformatted JSON, and see which checks each copy fails, including the original sent to the wrong reader.