Base64 Encode / Decode
Convert between text/files and Base64. Runs locally — nothing is uploaded.

Utilities

Base64 Encode/Decode

Convert between text/files and Base64 encoding.

Base64 Encode / Decode converts between plain text (or whole files) and Base64 entirely on-device. The Encode tab accepts typed text, or a file via the Choose file button on the Input row; the Decode tab takes a Base64 string typed or pasted directly, or loaded from a .b64 / .txt file with its own Choose file button — whitespace and newlines are stripped first, so PEM-style wrapped blocks paste cleanly. Output auto-refreshes on every input and tab change, with Copy, Download, and Clear always one click away.

Encoding is UTF-8 safe via an encodeURIComponent round-trip, so emoji and CJK text survive intact. Files are read as ArrayBuffers, converted to binary strings, and passed through btoa; decoding rebuilds a File you can download under the original name (with .b64 stripped) or as decoded.txt / encoded.b64. The card is explicit: "Runs locally — nothing is uploaded."

How it works

lib/base64.ts encodes with btoa(unescape(encodeURIComponent(text))) and decodes with decodeURIComponent(escape(atob(...))) after stripping whitespace. Files go through encodeFile (ArrayBuffer → binary string → btoa) and decodeFile (reverse into a File of type application/octet-stream). validateBase64 removes whitespace, checks /^[A-Za-z0-9+/]*={0,2}$/, and performs a trial atob before anything renders.

The page re-runs conversion in a setTimeout-0 effect whenever input or tab changes. Downloads are Blobs created locally: encode saves {file.name}.b64 or encoded.b64, decode restores the original filename or falls back to decoded.txt. Failures surface as a destructive Alert — "Invalid Base64 string", "Failed to encode file", "Failed to decode Base64", or "Failed to create download".

How to use

  1. Choose the "Encode" or "Decode" tab at the top of the card.
  2. On Encode, type or paste text, OR click "Choose file" on the Input row to pick a file (it becomes "Change file" when one is selected; "Remove file" clears it so you can type again).
  3. On Decode, paste a Base64 string or click "Choose file" to load a .b64 / .txt file into the input (whitespace and newlines are tolerated — validateBase64 cleans them before checking).
  4. Watch the "Output" field update automatically on input or tab change (a setTimeout-0 effect drives it; "Processing…" with a spinner shows during file reads).
  5. Handle errors: "Invalid Base64 string" appears if the alphabet/padding check or trial atob fails.
  6. Use "Copy" or "Download" on the output row — downloads save as .b64, encoded.b64, or decoded.txt / the restored file.
  7. Click "Clear" to reset input, file, output, and error together in one action.

Tips

  • Encoding handles Unicode correctly through the encodeURIComponent round-trip — paste emoji or CJK text without worry.
  • Decoding strips all whitespace first, so PEM-style wrapped Base64 pastes work without manual reflow.
  • File encode shows the name and size in kilobytes on a row above the textarea (e.g. report.pdf (12 KB)) plus the same detail in the disabled textarea placeholder.
  • Downloads are Blobs created in-browser; the card states "Runs locally — nothing is uploaded."

Base64 Encode/Decode FAQ

Is my file uploaded?

No — the CardDescription says "Convert between text/files and Base64. Runs locally — nothing is uploaded." Files are read with FileReader on-device only.

Why do I see "Invalid Base64 string"?

validateBase64 rejects the input if it fails /^[A-Za-z0-9+/]*={0,2}$/ after whitespace removal, or if a trial atob call throws.

Can I decode back to a binary file?

Yes — if you previously selected a file, decode + Download uses decodeFile to rebuild a File you can save with the original name (.b64 stripped).

What does "Processing…" mean?

File encode is asynchronous (FileReader); the spinner shows while encodeFile reads the file into a binary string for btoa.

Credits

ShareTweet
More Utilities

Command Palette

Search for a command to run...