PKCE Code Verifier and Code Challenge Generator

Generate a code_verifier or paste your own, and get the S256 code_challenge for OAuth 2.0 PKCE (RFC 7636).

code_challenge (S256)

Runs entirely in your browser. Nothing you enter is sent or stored.

How to use

  1. Press Generate for a new random code_verifier, or paste one.
  2. The code_challenge is computed as BASE64URL(SHA-256(code_verifier)).
  3. Send code_challenge with code_challenge_method=S256 in the authorization request.
  4. Send the code_verifier in the token request.

PKCE (Proof Key for Code Exchange, RFC 7636) protects the OAuth 2.0 authorization code flow. It was designed for public clients such as mobile apps, desktop apps and single-page web apps, which cannot keep a client secret. Before redirecting the user, the client creates a one-time secret called the code_verifier and sends only its hash, the code_challenge. When it later exchanges the authorization code for tokens, it sends the original verifier and the server checks that the two match, so someone who intercepts the code alone cannot use it.

This generator takes 32 random bytes from the browser’s crypto.getRandomValues and encodes them as base64url without padding, which gives a 43-character verifier. The challenge is the SHA-256 of the verifier, again base64url-encoded without padding, and is always 43 characters long. Only the S256 method is offered: RFC 7636 also defines plain, but requires S256 whenever the client can compute SHA-256. Use it to debug a login integration, compare your library’s output, or build test requests by hand.

A pasted verifier is hashed as-is and is not checked against the RFC rules, so make sure yours has 43 to 128 characters from A–Z, a–z, 0–9, “-”, “.”, “_” and “~”. Create a new verifier for every authorization request. Both values are computed on this page with the Web Crypto API and are never sent anywhere.

Frequently asked questions

What is PKCE?

Proof Key for Code Exchange (RFC 7636). The client sends a hashed code_challenge with the authorization request and the original code_verifier with the token request, so a stolen authorization code cannot be redeemed alone.

How is the code_challenge calculated?

With method S256: SHA-256 of the ASCII code_verifier, then base64url-encoded without padding. For the RFC 7636 example verifier dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk the result is E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM.

Why is the generated verifier 43 characters?

32 random bytes encoded as base64url without padding are 43 characters, the minimum length RFC 7636 allows (43 to 128 characters of A-Z, a-z, 0-9, -, ., _, ~).

Related tools