Encoding vs hashing vs encryption: Base64, SHA, JWT explained
Encoding changes how data is written and anyone can undo it; hashing produces a fixed-size fingerprint that cannot be undone; encryption can be undone only with a key. A JWT is encoded and signed, not encrypted.
ConvertBoxPublished
Three operations with three different purposes
Mixing up the three terms causes real security bugs: a password 'encrypted' with Base64, a token trusted because it decoded cleanly. The distinction is about who can reverse the operation.
| Encoding | Hashing | Encryption | |
|---|---|---|---|
| Purpose | Make data fit a channel that accepts only certain characters | Produce a short fingerprint to compare or verify data | Keep data secret from anyone without the key |
| Key or secret | None | None (HMAC adds one) | Required |
| Reversible | Yes, by anyone | No | Yes, with the key |
| Output size | Grows with the input | Fixed: 256 bits for SHA-256 | About the size of the input |
| Examples | Base64, percent-encoding, hex | SHA-256, SHA-512, MD5 | AES, RSA, ChaCha20 |
Base64: the arithmetic behind the 33% growth
Base64 (RFC 4648) exists to carry arbitrary bytes through text-only channels such as email bodies, JSON strings and HTML attributes. It reads 3 bytes, 24 bits, and writes them as four 6-bit groups, each mapped to one of 64 characters: A-Z, a-z, 0-9, + and /. Four output characters for every three input bytes is a ratio of 4/3, hence the 33% growth. When the input is not a multiple of 3, = pads the last group: Man encodes to TWFu, Ma to TWE= and M to TQ==.
For n input bytes the output length is 4 Γ ceil(n / 3). A 1 MB file of 1,048,576 bytes becomes 1,398,104 characters. Size depends on bytes, not characters: the site's Base64 tool converts text to UTF-8 first, so Γ© is 2 bytes and most Chinese, Japanese and Korean characters are 3. It handles text only; a decoded image or PDF is not valid UTF-8 and is reported as an error, so decode binary payloads with a command-line tool.
Base64 versus Base64URL
Standard Base64 uses + and / and pads with =. All three characters have meanings inside URLs, so RFC 4648 also defines a URL-safe alphabet that substitutes - and _ and usually drops the padding. The two bytes FB FF encode to +/8= in standard Base64 and to -_8 in Base64URL. Nothing else differs, which is why a JWT segment pasted into an ordinary Base64 decoder fails only when it happens to contain one of those characters.
The site's Base64 tool encodes in the standard alphabet with padding, on one unwrapped line. Its decoder ignores line breaks and tolerates missing padding but does not accept - or _; replace them with + and / first.
Percent-encoding: what must be escaped in a URL
A URL may contain only a limited set of ASCII characters, and some of them, such as ? & = / #, act as delimiters. Percent-encoding (RFC 3986) writes any other byte as % followed by two hex digits. Non-ASCII text is converted to UTF-8 first, so Γ© becomes %C3%A9.
The site's URL encoder uses JavaScript's encodeURIComponent, which follows these rules and additionally leaves ! * ' ( ) unescaped. Signature schemes that hash the encoded string, such as OAuth 1.0 and AWS Signature Version 4, need those five escaped as well.
- Never escaped: letters, digits and the four marks - . _ ~ (the unreserved set).
- Encode values, not whole URLs. The value a b&c=d must become a%20b%26c%3Dd before it goes into a query string; encoding a full address also escapes its :// and breaks the link.
- A space is %20 in a URL but + in HTML form submissions. A decoder that follows RFC 3986 leaves + as a plus sign.
- Encoding twice turns %20 into %2520. A decoded result that still shows %XX sequences was encoded twice.
Hashing: one-way fingerprints, and why fast hashes fail for passwords
A cryptographic hash maps input of any size to a fixed-size digest: SHA-256 always yields 256 bits, written as 64 hex characters. The same input always gives the same digest, a one-character change gives an unrelated one, and there is no way to compute the input from the output. MD5 and SHA-1 are excluded from security uses because collisions, two different inputs with the same digest, can be produced deliberately; MD5 remains acceptable only as a checksum against accidental corruption.
Passwords are a separate problem, and here even SHA-256 is the wrong tool. General-purpose hashes are built to be fast, so an attacker holding a leaked table can test guesses at an enormous rate on GPUs, and identical passwords produce identical hashes that can be looked up in precomputed lists. Password storage uses deliberately slow, salted functions: Argon2, bcrypt, scrypt or PBKDF2. Each stores a random salt per password and has a tunable cost.
The site's hash generator computes MD5, SHA-256, SHA-384 and SHA-512 over the UTF-8 bytes of pasted text, including trailing spaces and line breaks. It does not offer SHA-1, does not compute HMAC and cannot read files; to check a download use sha256sum, shasum -a 256 or certutil -hashfile.
Encryption: reversible only with the key
Encryption turns data into ciphertext that is meaningless without a key. Symmetric ciphers such as AES use one shared key for both directions; asymmetric systems such as RSA and elliptic-curve cryptography use a public key that anyone may hold and a private key that is kept secret. HTTPS combines both: asymmetric cryptography to agree on a key, then a symmetric cipher for the traffic.
The practical test: if no secret is needed to read the data, it is not encrypted. An HTTP Basic authentication header is the Base64 of user:password; dXNlcjpwYXNz decodes to user:pass for anyone who sees it, and only the TLS connection around it provides secrecy.
JWT: signed, not encrypted
A JSON Web Token (RFC 7519) is three Base64URL segments joined by dots: header, payload, signature. The header eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 is simply the encoding of {"alg":"HS256","typ":"JWT"}. The payload is equally readable, so it must never hold passwords or sensitive personal data. What protects a JWT is the third segment: an HMAC computed with a shared secret (HS256) or a signature made with a private key (RS256, ES256). Changing one character of the payload invalidates it.
Decoding is therefore not verifying. Anyone can craft a payload that decodes perfectly; only recomputing the signature with the secret or the issuer's public key proves that a token is authentic, and a server must also check exp, which counts seconds since 1970 UTC. The site's JWT decoder shows the header and payload as formatted JSON and leaves the signature as it is. It does not verify, and it rejects five-part tokens, which are encrypted JWEs that cannot be read without the key. Use it to debug an expired token or a wrong audience, not to decide whether to trust one.
Picking the right operation for common tasks
- Putting binary data in JSON or a data URI: Base64.
- Putting a value in a query string: percent-encoding; for Base64 data in a URL, the Base64URL alphabet.
- Checking that a file arrived intact: SHA-256 against the published checksum.
- Storing user passwords: Argon2, bcrypt, scrypt or PBKDF2 with a per-password salt.
- Proving a message came from a holder of a secret: HMAC or a digital signature.
- Keeping content unreadable to others: encryption, with the key stored apart from the data.