TToolbox
64U

Base64URL Encode/Decode

URL-safe variant, convertible with standard Base64

About this tool

Base64URL encoding (RFC 7515, RFC 4648 Section 5) is the URL-safe cryptographic encoding standard powering JSON Web Tokens (JWT), OAuth 2.0 PKCE code verifiers, and WebAuthn credentials. Standard Base64 contains `+` and `/` characters, which clash with URL query delimiters and path hierarchies (`+` decodes to spaces, `/` splits route segments), while trailing `=` padding breaks URL gateways. Base64URL safely substitutes `+` with `-` and `/` with `_`, stripping trailing padding entirely. This tool provides bidirectional conversion locally.

How to Use This Tool (Step-by-Step)

1

Enter Plaintext or Encoded Token

Paste your raw text, standard Base64 string, or JWT Base64URL segment into the input window.

2

Select Conversion Action

Select your action: Text to Base64URL, Base64URL Decode to Text, or toggle between Standard Base64 and Base64URL.

3

Copy URL-Safe Result String

The sanitized output renders instantly without unsafe slashes or padding. Copy with one click to embed inside HTTP headers.

RFC 7515 Standard Mapping

Strictly translates `+` to `-`, `/` to `_`, and strips trailing `=` padding characters for unescaped URI routing.

Standard Base64 vs Base64URL Toggle

Enables direct conversion between traditional Base64 and modern Base64URL without intermediate plaintext decoding roundtrips.

100% Client-Side Air-Gapped

Transformations run entirely inside local browser memory. Sensitive OAuth session secrets and PKCE tokens are never logged.

Base64URL Integration & Padding Tips

  • •Restore padding before decoding: Native `atob()` crashes if string lengths are not multiples of 4. Always re-append `=` padding based on `length % 4`.
  • •PKCE Code Challenges mandate Base64URL: OAuth 2.0 specifications require hashing the code verifier and encoding strictly with Base64URL.
  • •Base64URL vs URL Percent-Encoding: Base64URL replaces characters directly (`-`, `_`); percent-encoding escapes into `%XX`. Do not double-encode.

Code & Transformation Examples

Standard Base64 vs Base64URL Syntax Benchmark

Standard Base64 (RFC 4648)
含字符: A-Z, a-z, 0-9, '+' 和 '/'
末尾填充: 包含 '=' 或 '=='
URL传输: 危险!'+' 易被误视为空格,'/' 破坏路径
Base64URL (URL-Safe)
含字符: A-Z, a-z, 0-9, '-' 和 '_'
末尾填充: 强制省略全部 '=' 填充符
URL传输: 100% 安全!可直接放在网址路径与参数中

* JWT tokens are constructed precisely by joining two Base64URL segments with a period.

JavaScript Base64 to Base64URL Conversion Snippet

Base64 to Base64URL
function base64ToBase64Url(base64) {
  return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
Base64URL to Base64
function base64UrlToBase64(base64url) {
  let b64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
  // 自动补齐等号填充
  while (b64.length % 4) b64 += '=';
  return b64;
}

* Re-padding `=` until length is a multiple of 4 is required before feeding strings to native `atob()`.

Frequently Asked Questions

Q: Why does Base64URL strip trailing `=` padding characters?

A: The `=` character is the reserved key-value delimiter in query strings (`?k=v`). Trailing padding frequently corrupts query parameter parsers on legacy proxies.

Q: Is Base64URL an encryption algorithm?

A: No. It is an unkeyed encoding format designed for safe transport. Anyone can decode it instantly without a key. Never use it to conceal plaintext passwords.

Q: Can Chinese characters be converted directly to Base64URL?

A: Yes. An integrated UTF-8 byte serialization pipeline cleanly encodes CJK characters and emojis without triggering browser `btoa` range exceptions.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/