SecretNote.eu

Base64 Is Not Encryption: Hashing vs Encoding vs Encryption

The short answer to encoding vs encryption: encoding changes how data is written so systems can carry it, and anyone can undo it without a key. Encryption scrambles data so that only someone holding the key can read it. Hashing is the third, separate idea: it turns data into a fixed-length fingerprint that cannot be turned back at all.

Sophie ParkerPublished · Updated · 9 min read
A note shown three ways: visible in a glass envelope, locked in a box with a key, and pressed into a fingerprint, illustrating encoding, encryption and hashing
Key takeaways The short version, before the details.
  • Encoding is a format change. No key, no secret, fully reversible by anyone.
  • Encryption is reversible only with the right key. It is the one that keeps data confidential.
  • Hashing is one way. It proves data has not changed, it does not hide data you need back.
  • Base64 is encoding. A Base64 string is plaintext in a different alphabet.

Encoding vs encryption: what is the difference?

The difference is the key. Encoding has none. The rules for turning the data back are public, so the output protects nothing. Encryption mixes the data with a secret key, and without that key the output is useless to whoever holds it.

Hashing gets confused with both because its output also looks like random characters. It answers a different question. Encoding asks "can this system carry my data?". Encryption asks "who is allowed to read it?". Hashing asks "is this the same data as before?".

Encoding

Makes data fit a channel

Reversible by anyone. No key exists. Examples: Base64, hex, URL encoding, UTF-8.

Encryption

Keeps data confidential

Reversible only with the key. Examples: AES, ChaCha20, RSA.

Hashing

Proves data is unchanged

Not reversible. Same input, same fingerprint. Examples: SHA-256, SHA-512, SHA-3.

Hashing vs encoding vs encryption compared side by side

EncodingEncryptionHashing
PurposeCompatibilityConfidentialityIntegrity and verification
Uses a keyNoYesNo (HMAC adds one)
ReversibleYes, by anyoneYes, with the keyNo
Output lengthGrows with the inputGrows with the inputFixed per algorithm
Hides the contentNoYesOnly if the input is hard to guess
Typical useEmail attachments, URLs, JSON fieldsMessages, files, disks, HTTPSChecksums, password storage, signatures

What is encoding and why is it not secret?

Encoding rewrites data in a different alphabet so that a system built for one kind of data can carry another. Email was designed for text, so binary attachments are rewritten as text. URLs cannot contain spaces, so a space becomes %20.

The scheme is published and works the same for everyone. Base64 is defined in RFC 4648: it takes three bytes at a time and writes them as four characters from a 64-character alphabet. That is why Base64 output is about a third larger than the input, and why it often ends in one or two = padding characters.

Why base64 is not encryption

Base64 is not encryption because nothing secret goes into it. There is no key to keep private, so there is nothing an attacker has to find. Decoding takes one command:

echo 'aGVsbG8=' | base64 --decode
# hello

The same goes for hex, URL encoding and ROT13. If a string can be turned back by anyone who recognises the format, it is plaintext.

Where Base64-encoded secrets get mistaken for protected ones

  • HTTP Basic authentication. The header carries username:password in Base64. RFC 7617 says plainly that this is not secure unless the connection itself is encrypted with TLS.
  • JSON Web Tokens. The header and payload of a signed JWT are Base64url encoded. Anyone holding the token can read the claims. The signature stops tampering, it does not hide anything.
  • Kubernetes Secrets. Values in a Secret manifest are Base64 encoded. A manifest pasted into a chat or committed to a repository exposes every value in it.
  • Config files and logs. A Base64 blob in a ticket or a log line looks scrambled enough that people stop treating it as a credential.

This Basic auth header contains the login admin:hunter2, readable by anyone who sees it:

Authorization: Basic YWRtaW46aHVudGVyMg==

Treat encoded secrets as plaintext

If a password, token or API key was only ever Base64 encoded and it has been seen by someone who should not have it, it is exposed. Rotate it.

What is encryption and what does the key do?

Encryption turns readable data (plaintext) into unreadable data (ciphertext) using an algorithm and a key. The algorithm is public. The key is the only secret, and it is what makes the process reversible for one party and not for everyone else.

There are two families:

  • Symmetric encryption uses one key to encrypt and decrypt. AES is the standard example. It is fast and used for files, disks and message bodies.
  • Asymmetric encryption uses a key pair: a public key to encrypt and a private key to decrypt. RSA and elliptic-curve schemes work this way, and they solve the problem of agreeing on a key with someone you have never met.

In practice the two are combined, and the security of the whole thing comes down to who holds the key. Our encryption guide covers the algorithms in depth, and the post on zero knowledge encryption explains what changes when the server never gets the key.

What is hashing and is hashing reversible?

No, hashing is not reversible. A hash function takes input of any size and produces a fixed-length output called a digest. SHA-256 always produces 256 bits, which is 64 hex characters, whether you hash one word or a 4 GB file.

Two properties make a hash useful. The same input always gives the same digest, and a tiny change in the input gives a completely different one:

SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA-256("Hello") = 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

You can try this yourself in the SecretNote hash generator. Type text and it shows MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-256 and RIPEMD-160 digests as you type, computed in your browser.

What a one way function means

A one way function is easy to compute in one direction and infeasible to compute in the other. Going from input to digest takes microseconds. Going from digest to input has no shortcut.

Part of the reason is that information is thrown away. An unlimited number of possible inputs map onto a fixed number of possible digests, so a digest does not contain the input in any form. There is nothing inside it to decrypt, which is why "decrypt this hash" is not a meaningful request.

How attackers crack hashes without reversing them

They guess. An attacker hashes a long list of likely inputs and compares each result with the stolen digest. When two digests match, the guess was right.

This works well against short or common inputs. The SHA-256 of "hello" above appears in every precomputed lookup table, so that digest hides nothing. Hashing only conceals an input that is long and unpredictable enough that nobody will ever guess it.

Hashing vs encryption: which protects passwords?

For storing user passwords, hashing. A site never needs to read your password back. It only needs to check that what you typed matches what you set, and comparing digests does that. If the passwords were encrypted, the server would hold a key that turns the whole database back into plaintext, and whoever steals the database tends to get the key too.

A plain fast hash is not enough, though. SHA-256 is designed to be quick, which helps an attacker make billions of guesses. Password storage needs a deliberately slow, salted algorithm. The OWASP Password Storage Cheat Sheet recommends Argon2id, with scrypt, bcrypt and PBKDF2 as alternatives.

For sending a password to another person, the answer flips to encryption. The recipient has to read the actual password, so it must be recoverable, but only by them.

When to use encoding, hashing or encryption

You want toUse
Put binary data in JSON, a URL or an emailEncoding (Base64, Base64url)
Check that a download arrived intactHashing (SHA-256 checksum)
Store user passwords in a databaseSlow salted hashing (Argon2id, bcrypt)
Prove a webhook or API request came from the holder of a shared keyKeyed hashing (HMAC)
Send a password, token or document to someoneEncryption
Protect data on a disk or in a backupEncryption

One quick test settles most cases. Ask whether you need the original back, and who should be able to get it. Everyone: encoding. Only key holders: encryption. Nobody: hashing.

How to tell if a string is encoded, hashed or encrypted

You cannot be certain from looks alone, but shape gives strong hints.

  • Base64: letters, digits, + and / (or - and _ in the URL-safe variant), often ending in =. Decode it. If readable text comes out, it was only encoded.
  • Hex digest: only 0-9 and a-f, at a telling length. 32 characters suggests MD5, 40 suggests SHA-1, 64 suggests SHA-256, 128 suggests SHA-512.
  • Password hash: a prefix such as $2b$ (bcrypt) or $argon2id$ (Argon2).
  • Ciphertext: has no recognisable structure. It is usually stored Base64 or hex encoded, so decoding it gives random-looking bytes instead of text.

The Identify tab of the hash generator does the length and prefix check for you: paste a string and it lists the most likely algorithms, or tells you the value looks like Base64. It is a best guess from length and shape, since several algorithms produce digests of the same length.

How an encrypted note uses all three

Real systems rarely pick one. A SecretNote note is a compact example, because the browser code uses all three, each for its own job:

  1. Hashing derives the key. The note key is run through PBKDF2 with SHA-256 and a random salt, 100,000 iterations, to produce a 256-bit AES key.
  2. Encryption protects the content. The note is encrypted in the browser with AES-256 in GCM mode, using a fresh random IV. GCM also detects tampering: altered ciphertext fails to decrypt.
  3. Encoding carries the result. The salt, IV and ciphertext are raw bytes, so they are Base64 encoded to travel as text.

The Base64 step adds no security and is not meant to. It wraps bytes that are already encrypted. Base64 around ciphertext is fine. Base64 around a plaintext password is the mistake.

Frequently asked questions about encoding, hashing and encryption

No. Base64 is an encoding. It has no key and its rules are public, so anyone can decode it instantly. It exists to carry binary data through systems that expect text, not to keep anything private.

No. A hash is not encrypted data, so there is nothing to decrypt. Sites that claim to reverse hashes look the digest up in a table of inputs that were hashed in advance. That finds common words and short passwords, and fails on long random input.

Stored passwords should be hashed with a slow, salted algorithm such as Argon2id or bcrypt, because the server only needs to verify them. Passwords you send to another person should be encrypted, because the recipient needs to read them.

Base64 works on groups of three bytes. When the input length is not a multiple of three, the last group is padded with one or two = characters so the output length stays a multiple of four. The padding carries no data.

No. Both are cryptographic tools, but encryption is two way and uses a key, while hashing is one way and has no key. Encryption is for data you need to read again. Hashing is for data you only need to compare or verify.