ToolsWhisper

Base64 Is Not Encryption

Base64 is an encoding, not a cipher. It has no key, protects nothing, and is trivially reversible — here is what it is actually for.

FrankUpdated 4 min read
An open padlock with the Base64 string c2VjcmV0 decoding to the word secret, showing that Base64 is not encryption

Roughly once a year a breach writeup includes the phrase "passwords were stored Base64 encoded". This is the security equivalent of locking your front door by writing the word LOCKED on it.

Encoding is not encryption

The distinction is simple:

  • Encoding transforms data into another format so it can survive transport. It is public, reversible by anyone, and has no key.
  • Encryption transforms data so that only a holder of the key can reverse it.

Base64 has no key. It cannot have one — that is not what it is for. Every Base64 decoder in the world, including the one on this site, will reverse it instantly:

cGFzc3dvcmQxMjM=   ->   password123

If you can read it, so can anyone who gets your database.

What Base64 is actually for

Base64 exists because a lot of systems are byte-hostile. Email headers, URLs, JSON strings, XML attributes and HTTP headers all have characters that mean something structural, and raw binary dropped into any of them will break something.

Base64 maps arbitrary bytes onto 64 characters that survive all of those channels unharmed. That is the entire purpose. Legitimate uses include:

  • Embedding binary in text — images as data: URIs, attachments in email
  • Binary in JSON — JSON has no byte type, so bytes are Base64 strings
  • HTTP Basic Auth — which is why Basic Auth requires HTTPS to be safe at all
  • JWT parts — the header and payload are Base64URL, which is exactly why our JWT decoder can read them without a key

Where this mistake shows up in real systems

It is not only a story from breach writeups. Base64 gets mistaken for protection in everyday tooling:

  • Kubernetes Secrets. The values in a Secret manifest are Base64 strings, which makes them look sealed. They are not. By default Kubernetes stores Secrets unencrypted in etcd, and anyone who can read the object can decode the value with one command. Encryption at rest has to be switched on separately, and access has to be limited with RBAC.
  • HTTP Basic Auth. The Authorization: Basic ... header is the username and password joined with a colon and Base64 encoded. Anyone who can see the header can read the credentials, which is why Basic Auth is only acceptable over HTTPS.
  • Docker's config.json. The auth field for a registry login is a Base64 encoding of username:password. Treat that file like a password file, because that is what it is.
  • Config files and mobile apps. An API key stored as a Base64 string in app code or a settings file is still an API key in plain sight. Anyone who unpacks the app can decode it in seconds.

How to recognise Base64, and why it fools people

Base64 output looks like random noise, which is exactly why it feels secure. It has a few tells: only letters, digits, + and / (or - and _ in the URL-safe form), a length that is a multiple of four once padding is included, and often one or two = characters at the end. What those equals signs mean is a matter of simple arithmetic, not secrecy.

Random-looking is not the same as protected. Real ciphertext also looks random, but you cannot reverse it without the key. A Base64 string gives itself up in a single step. You can prove it to yourself in a terminal:

echo -n 'password123' | base64
# cGFzc3dvcmQxMjM=

echo 'cGFzc3dvcmQxMjM=' | base64 --decode
# password123

Or in a browser console, with btoa('password123') to encode and atob('cGFzc3dvcmQxMjM=') to decode. No key was asked for, because there is none.

Encoding it twice does not help

Some people layer it: Base64 the string, then Base64 the result, perhaps reverse it or swap a few characters. That is obfuscation, not security. Every layer is a fixed, public transformation with no secret in it, so an attacker simply decodes repeatedly until readable text comes out, which is a loop of a few lines.

The principle behind this is old and worth remembering: a system should stay secure even if everything about it except the key is public. Base64 has no key, so there is nothing left to keep secret. Strength comes from a secret the attacker does not have, never from the number of steps.

The cost

Base64 makes data about 33% larger — every 3 bytes become 4 characters. For an inline icon that is a fine trade. For a multi-megabyte upload it is pure waste, and you should be sending raw bytes.

What to use instead

For passwords: a slow hash designed for the purpose — Argon2id, scrypt, or bcrypt. Not SHA-256 either; general-purpose hashes are too fast, which is precisely what an attacker wants.

For data you need to read back: real encryption with a real key — AES-GCM, with the key in a secrets manager rather than next to the data.

For proving something has not changed: a hash. Our hash generator does SHA-256 through the browser's Web Crypto API.

If you find Base64 "protecting" something

Treat it as a leak, not a style issue:

  1. Assume the value is exposed. Anyone with access to the repository, database, backup or log file has had it.
  2. Rotate it. Change the passwords, and revoke and reissue API keys and tokens that were stored this way.
  3. Move it. Secrets belong in a secrets manager or the secret store of your platform, injected at runtime, not committed beside the code.
  4. Stop storing passwords reversibly. Hash them with Argon2id, scrypt or bcrypt, and re-hash existing users the next time they sign in.
  5. Check your logs for any use of the old values after you rotate them.

Quick answers

  • Is Base64URL any different? Only in the alphabet: - and _ replace + and /. It still has no key.
  • Does HTTPS make Base64 fine? HTTPS protects data in transit. It does nothing for a value sitting in a database, a file or a log.
  • Is it acceptable as light obfuscation? To stop a casual glance, perhaps, but call it what it is and never put anything in it that you would mind being read.

Base64 remains genuinely useful, just never as a security measure. If a tool can decode it with no key, so can everybody else.

Tools used in this article

Read next