GUIDE

Encoding, hashing and encryption: three different jobs

Base64 and URL encoding hide nothing, a hash is a one-way fingerprint and encryption needs a key. What each protects against, shown with real examples.

By StillKit · Updated

Encoding, hashing and encryption all turn data into strings that look like gibberish, which is why people confuse them. They do different jobs. Encoding rewrites data so it can travel through text, and anyone can reverse it. Hashing makes a short fingerprint that cannot be turned back into the data. Encryption hides data so that only someone with the key can read it.

Three jobs side by side
JobWho can reverse itKeyExample tool
EncodingAnyoneNoneBase64 encoder and decoder
HashingNobody, except by guessing the inputNone (HMAC adds one)SHA hash generator
EncryptionWhoever has the key or passwordRequiredAES-GCM text encryption

Encoding changes the format, and anyone can reverse it

Base64 writes any bytes with 64 characters that survive email, JSON and web forms: A–Z, a–z, 0–9, + and /, with = as padding at the end. Every 3 bytes become 4 characters, so the result is about a third longer. The Base64 encoder and decoder turns Hello into SGVsbG8=, and its Decode Base64 to text direction turns it straight back. No key is involved at any point. StillKit's decoder is strict: it rejects SGVsbG8, the same text without its padding, rather than guess.

URL encoding, also called percent-encoding, replaces characters that have a meaning inside a web address. The URL encoder and decoder turns hello world & privacy into hello%20world%20%26%20privacy; left as it was, the & would start a new query parameter. Hexadecimal is the plainest encoding of all: each byte becomes two digits, so Hello is 48656c6c6f.

Encoding protects against accidental damage in transit, and nothing else. A password stored in Base64 is a password in plain view. JSON Web Tokens show this well. The middle part of a token is Base64url-encoded JSON, and the JWT payload inspector reads it without any key, so anyone who holds a token can read what it says. The signature shows only whether a key holder issued the token unchanged. The inspector does not check that signature, and labels every result "UNVERIFIED".

A hash is a one-way fingerprint

A hash function turns input of any size into a value of fixed size. SHA-256 gives 256 bits, shown as 64 hexadecimal characters, and the same input gives the same hash on every device. The smallest change gives an unrelated result. In the SHA hash generator, set to SHA-256, hello gives a hash that starts 2cf24dba, while Hello gives one that starts 185f8db3: 125 of the 256 bits differ. A trailing space or line break changes the hash as well, because the tool hashes the exact UTF-8 bytes you enter.

There is no key and no way back. The only route from a hash to its input is to guess inputs, hash each one and compare. That makes hashes good at showing that data has not changed. The File checksum tool reads a file of up to 20 MB; if its result matches the checksum a software publisher lists, your copy is identical to theirs. The check is only as trustworthy as the place the reference value came from. A checksum printed on the same tampered page as a tampered download proves nothing.

Hashing does not keep a guessable value secret. Phone numbers, birth dates and short passwords can be hashed one by one until one matches, so a list of hashed phone numbers is barely protected. A plain hash is also too fast for storing passwords, which is the problem PBKDF2 solves below.

An HMAC mixes a secret key into the hash. Only someone with the key can produce the right tag. A matching tag therefore shows that the message came from a key holder and was not changed on the way. The HMAC generator computes such tags with SHA-256 or SHA-512, of the kind many services use to sign the messages they send to other systems. An HMAC proves integrity but hides nothing: the message itself travels as plain text.

Encryption needs a key, and authenticated encryption also detects changes

The AES-GCM text encryption tool performs each step of password-based encryption. In order, it:

  1. creates a random 16-byte salt and a random 12-byte IV, a value used only once;
  2. runs PBKDF2-SHA-256 with 600,000 iterations to turn your password, 12 to 1,024 characters long, and the salt into a 256-bit key;
  3. encrypts your text, up to 100,000 characters, with AES-256-GCM, which adds a 128-bit authentication tag;
  4. returns a JSON envelope listing the format, version, algorithm, kdf, iterations, kind, salt, iv and ciphertext.

The salt and IV are not secrets. Decryption needs them, so they travel inside the envelope, and the password is the only secret. Because both are new every time, encrypting the same text twice with the same password gives two different envelopes. Nobody can tell from outside that the two messages match.

GCM is authenticated encryption: its tag lets decryption detect any change to the ciphertext. In AES-GCM text decryption, changing a single character of the ciphertext, or entering the wrong password, stops the job with "Authentication failed: wrong password or modified encrypted data." It cannot tell those two cases apart, and it shows no partial text. Without authentication, altered ciphertext can decrypt to altered text with no warning at all.

The AES-GCM file encryption tool works the same way on files up to 10 MB and saves encrypted.stillkit. The original file name is not stored, so file decryption saves decrypted.bin, which you rename with the right extension. The envelope also records whether it holds text or a file, and that label is checked during decryption, so a file envelope cannot be opened as text.

Encryption hides the content, not everything about it. Anyone who sees an envelope can tell that it is a StillKit envelope and whether it holds text or a file. The envelope also reveals the original's size: before Base64 encoding, the ciphertext is exactly 16 bytes longer than the data.

PBKDF2 and a salt turn a password into a key

AES-256 needs a key of 32 bytes that look completely random. A password is usually shorter and far from random, so it cannot be used directly. A key derivation function turns it into a key, and PBKDF2 does this by repeating an HMAC calculation many times. StillKit uses 600,000 iterations of HMAC-SHA-256. You wait a moment once, while an attacker who tries a million guesses pays that cost a million times.

The salt is a random value mixed in before the iterations. Two people with the same password get different keys. An attacker also cannot build one table of keys for common passwords in advance, because every guess must be repeated for each salt. A salt does not need to be secret, only new for every password or file.

Neither measure rescues a weak password. Iterations make each guess slower and salts stop guesses being reused, but a password near the top of a leaked list still falls early. For encryption, use a long generated password, as explained in how strong is a password, and keep it in a password manager. Without it, nobody can open the envelope.

The PBKDF2 key derivation tool exposes the same function, so you can check another program's output. Enter a Password, a Salt as hexadecimal (16–64 bytes) and Iterations (100,000–1,000,000), and it returns 256 bits as 64 hexadecimal characters. Its example salt, 00112233445566778899aabbccddeeff, is fixed so that results can be compared. For a real record, make a fresh salt, such as 16 random bytes in Hex from the secure random token generator.

TRY IT YOURSELF

Tools used in this guide

Find your next shortcut

Search loads only when needed. Your search stays on your device.

Browse all categories and sections →