TheFileTools

How to encode text as Base64

Convert text to Base64 for an HTTP header, a config value or a data field, with a worked example and what Base64 does not protect.

Base64 writes any data using only letters, digits and a few symbols. It is used where raw text could be damaged or misread: HTTP Basic authentication headers, values in configuration files, JSON fields and email.

Steps

  1. Open Base64 encode.
  2. Type or paste the text. The result updates as you type.
  3. Press Copy.

There are no options. The text is first turned into UTF-8 bytes, so accents, non-Latin scripts and emoji all work, and the result uses the standard alphabet (A to Z, a to z, 0 to 9, + and /) with = padding, on one line without breaks.

Worked examples

  • Hello, world becomes SGVsbG8sIHdvcmxk
  • user:pass becomes dXNlcjpwYXNz, which is the form a Basic authentication header carries after the word Basic.
  • café becomes Y2Fmw6k= with one padding character, because the text is five bytes long in UTF-8.

Every character counts, including a space or line break at the end of the input. If a result does not match what another system produced, a trailing newline is the usual reason.

Base64 is not encryption

Anyone can reverse it with Base64 decode, without a key. Encoding a password hides it from a casual glance and nothing more. It also makes data bigger: every three bytes become four characters, so the output is about a third larger than the input.

Related cases

  • A file, not text: use File to Base64, which can also add the data: prefix needed to embed an image in HTML or CSS.
  • The URL-safe variant: some systems, JSON Web Tokens among them, replace + with - and / with _ and drop the padding. This tool outputs the standard form, so make those replacements yourself if they are required.
  • Putting text into a web address: that calls for percent-encoding, which is what URL encoder / decoder does.