# PKCE Code Verifier & Challenge Generator

Generate, validate and verify OAuth2 / OIDC PKCE (RFC 7636) code_verifier and S256 code_challenge pairs. Three modes: (1) generate a fresh verifier + challenge from cryptographically secure random bytes at 256/384/512/768-bit entropy, (2) audit a verifier you already have against the RFC — length (43–128), charset [A-Za-z0-9-._~] and ≥256-bit entropy, and (3) verify a verifier/challenge pair by recomputing BASE64URL(SHA256(verifier)). Optionally build the full authorization-request URL and token-exchange body. Complements the generic nonce-generator (which only emits a verifier+challenge pair) with RFC-compliance auditing and pair verification.

> Canonical page: https://elysiatools.com/en/tools/pkce-code-verifier-generator

- **Category:** Security

- **Keywords:** pkce, oauth2, oidc, rfc 7636, code_verifier, code_challenge, s256, authorization code, spa, mobile, public client, sha256, verifier, challenge, oauth security

## Overview

A focused PKCE (Proof Key for Code Exchange, RFC 7636) tool for OAuth2 / OIDC developers:

1. Pick a mode: Generate (a fresh pair), Validate (audit a verifier you have), or Verify (check a verifier/challenge pair match).
2. Generate mode derives a code_verifier from cryptographically secure random bytes (choose 32/48/64/96 bytes = 256/384/512/768 bits) and base64url-encodes it, then computes code_challenge = BASE64URL(SHA256(verifier)). The verifier stays client-side; only the challenge goes to the authorization server.
3. Validate mode audits an existing verifier against RFC 7636: length 43–128 characters, charset restricted to [A-Za-z0-9-._~], and ≥256 bits of entropy. If compliant it also shows the S256 challenge the verifier implies.
4. Verify mode recomputes BASE64URL(SHA256(verifier)) and compares it to a provided code_challenge — useful when debugging "invalid_grant" or mismatched challenge errors during the token exchange.
5. Optionally fill in the authorization endpoint, client ID and redirect URI to build the full authorization-request URL (with code_challenge_method=S256) and the token-exchange body that later sends the secret verifier.

Offline and cryptographically sound: random bytes come from the platform CSPRNG; SHA256 via the crypto module. No network calls, no value leaves the browser.

## Inputs

- **Mode** (select)
- **Verifier length (bytes of entropy)** (select)
- **Existing code_verifier (to validate/verify)** (textarea): Paste a code_verifier here (used in Validate and Verify modes)
- **Existing code_challenge (pair-verify mode)** (textarea): Paste the code_challenge to compare against (Verify mode)
- **Authorization endpoint (optional, for URL builder)** (text): https://auth.example.com/oauth2/authorize
- **Client ID (optional, for URL builder)** (text): my-client-id
- **Redirect URI (optional, for URL builder)** (text): https://app.example.com/callback

## When to use

- When implementing OAuth2 Authorization Code Flow with PKCE for single-page applications (SPAs) or mobile apps.
- When debugging 'invalid_grant' or mismatched challenge errors during the token exchange step of your authentication flow.
- When auditing an existing code verifier to ensure it meets RFC 7636 requirements for length, character set, and entropy.

## How it works

- Select your operation mode: Generate a new pair, Validate an existing verifier, or Verify a verifier/challenge pair.
- For generation, choose the entropy size (256 to 768 bits) to derive a secure code_verifier via the platform's CSPRNG and compute the S256 code_challenge.
- For validation or verification, input your existing verifier and challenge to run RFC 7636 compliance checks or compare computed SHA256 hashes.
- Optionally input your authorization endpoint, client ID, and redirect URI to automatically construct the authorization request URL and token exchange payload.

## Use cases

- Generating secure PKCE credentials for a new React or mobile application authentication setup.
- Troubleshooting OAuth2 integration issues by verifying if a logged code_verifier matches the sent code_challenge.
- Auditing custom PKCE implementation outputs to guarantee strict adherence to RFC 7636 specifications.

## Frequently asked questions

### What is PKCE?

Proof Key for Code Exchange (RFC 7636) is an extension to the OAuth2 authorization code flow designed to prevent authorization code interception attacks on public clients.

### Does this tool send my code verifier to a server?

No, all generation, hashing, and validation operations run entirely client-side in your browser using the Web Crypto API.

### What are the RFC 7636 requirements for a code verifier?

It must be a high-entropy cryptographic string between 43 and 128 characters long, containing only unreserved characters: letters, numbers, hyphens, periods, underscores, and tildes.

### What is the difference between code_challenge and code_verifier?

The code_verifier is a secret random string kept on the client, while the code_challenge is the BASE64URL-encoded SHA256 hash of that verifier sent to the authorization server.

### Why am I getting an 'invalid_grant' error during token exchange?

This usually happens because the code_verifier sent during the token exchange does not hash to the code_challenge sent during the initial authorization request.

## Related tools

- [Hash Algorithm Comparator](https://elysiatools.com/en/tools/hash-algorithm-comparator): Hash the same input with MD5, SHA-1, SHA-256, SHA-512, BLAKE2b, and BLAKE3 at the same time and compare them side by side: output length, hex/Base64 digest, security status (broken / modern), and a relative speed benchmark. Great for teaching, choosing a hashing algorithm, or sanity-checking checksums.
- [BIP39 Mnemonic Phrase Generator](https://elysiatools.com/en/tools/mnemonic-bip39-generator): Generate or validate 12 to 24 word BIP39 mnemonic phrases with entropy and PBKDF2-HMAC-SHA512 seed output
- [Text Hash Generator](https://elysiatools.com/en/tools/text-hash-generator): Compute MD5, SHA-1, SHA-256, SHA-512, and CRC-32 hashes of any text in one shot. Get both hex and Base64 digests over the UTF-8 encoding.
- [RSA Encrypt / Decrypt](https://elysiatools.com/en/tools/rsa-encrypt-decrypt): Encrypt text with an RSA public key or decrypt ciphertext with the matching private key, using OAEP padding (SHA-1 or SHA-256). Handles long messages by chunking. Keys and data stay local. PKCS#1 v1.5 is intentionally not offered (Node disables it for decryption due to Bleichenbacher attacks).
- [SSH Key Pair Generator](https://elysiatools.com/en/tools/ssh-key-generator): Generate an SSH key pair (Ed25519 recommended, RSA 4096, or ECDSA P-256) with an OpenSSH-format public key ready for ~/.ssh/authorized_keys, a SHA256 fingerprint, and a PEM private key. Optional passphrase encryption. Runs locally.
- [Thyroid Index (TSH/FT4/FT3 Interpretation)](https://elysiatools.com/en/tools/thyroid-index): Interpret the thyroid axis by pattern-reading TSH with FT4 and (optionally) FT3. Adult reference ranges: TSH 0.4–4.0 mIU/L, FT4 0.8–1.8 ng/dL (≈10–23 pmol/L), FT3 2.3–4.2 pg/mL (≈3.5–6.5 pmol/L). High TSH + low FT4 → overt primary hypothyroidism; high TSH + normal FT4 → subclinical hypothyroidism; low TSH + high FT4/FT3 → overt primary hyperthyroidism; low TSH + normal FT4 → subclinical hyperthyroidism, exogenous hormone, or resolving thyroiditis (check FT3 for T3 toxicosis); low/normal TSH + low FT4 → central hypothyroidism; high TSH + high FT4 → TSH-secreting adenoma or thyroid hormone resistance. Low FT3 with normal TSH/FT4 indicates low-T3 (non-thyroidal illness) syndrome. Units selectable for TSH, FT4, FT3. Derived from ATA 2014/2016, NACB 2002, Garber 2012, and MDCalc. Not medical advice.
- [TOTP / HOTP Offline Code Generator](https://elysiatools.com/en/tools/totp-hotp-offline-generator): Generate RFC 6238 TOTP (time-based, 6/8 digits, 30/60s step) and RFC 4226 HOTP (counter-based) one-time passwords from a base32 shared secret, fully offline with HMAC-SHA1/256/512, plus an otpauth:// URI for importing into Google Authenticator / Authy
- [AI Domain Name Idea Generator](https://elysiatools.com/en/tools/ai-domain-name-idea-generator): Generate up to 10 creative domain names with AI and filter out already-registered ones via DNS + RDAP.

## Samples

- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [Code Comment Samples](https://elysiatools.com/en/samples/code-comment-samples): Sample code files with various comment styles for testing comment removal
- [Web Image Processing Python Samples](https://elysiatools.com/en/samples/web-image-processing-python): Web Python image processing examples using PIL/Pillow including reading, saving, resizing, and format conversion
- [Invalid Variable Names Code Samples](https://elysiatools.com/en/samples/code-invalid-variable-names-samples): Sample code files demonstrating invalid variable naming conventions across different programming languages

## Related content

- [Audio Encoding and Format Conversion Tools](https://elysiatools.com/en/hubs/audio-convert): Compare audio format conversion, bitrate changes, sample-rate conversion, codec swaps, and export tools in one hub for delivery and archive workflows.
- [Image Format Conversion and Animated Export Tools](https://elysiatools.com/en/hubs/image-convert): Compare image format converters for JPG, PNG, GIF, AVIF, WebP, TIFF, ICO, base64, and animation-friendly exports in one hub.
- [JSON Interchange and Format Translation Tools](https://elysiatools.com/en/hubs/json-convert): Compare JSON conversion tools for CSV, YAML, TOML, GraphQL, XML, Markdown, Excel, BSON, EDN, and related structured formats in one hub.
- [Color Space Conversion Tools for Web and Print](https://elysiatools.com/en/hubs/design-convert): Curated tools for web-to-print color space conversion in one hub.
