Encoding vs encryption vs hashing vs signing

crypto · folio

In one line: Encoding changes the format — anyone reverses it, no secret. Encryption hides content — reversible with a key. Hashing fingerprints — one-way, no key. A MAC (shared key) or a signature (private key) proves who produced the bytes and that they are unchanged. A KDF turns a secret into keys — slowly, when the secret is a password. Choose by the property needed: format, confidentiality, integrity, authenticity, non-repudiation.

Download PDF Print view LaTeX source

Encoding vs encryption vs hashing vs signing — figure 1

What each one guarantees — and what it does not

givesdoes not givestandard
encodebytes safe in text: JSON, URL, headerany secrecy or integrityRFC 4648, 3986, 3629
encryptconfidentiality; AEAD adds integritylength hiding — GCM output = input + 16 BFIPS 197, RFC 5116
hasha fingerprint: equal digest ⇒ equal bytestamper-proofing, unless the digest comes by a trusted pathFIPS 180-4, 202
MACintegrity + origin among key holdersproof to a third partyRFC 2104
signintegrity + origin + non-repudiation; anyone verifiesconfidentialityFIPS 186-5, 204, 205
KDFkeys or a verifier from a secret— reversal is not its jobRFC 5869, 8018, 9106

Encodings — RFC 4648 and its neighbours

namealphabetbitssizepadding / note
Base16 (hex)0-9 A-F4×2none
Base32A-Z 2-75×8/5= to 8 chars; case-insensitive channels
base32hex0-9 A-V5×8/5keeps the bytes’ sort order
Base64A-Z a-z 0-9 + /6×4/3= to 4 chars
base64url… - _ for + /6×4/3= often skipped; JWS: always
percent%XX—×3 per escaped byteRFC 3986 passes A-Z a-z 0-9 - . _ ~

  • RFC 4648: MUST pad, MUST reject characters outside the alphabet, no line breaks — each “unless the referring spec says otherwise”: MIME wraps at 76, PEM (RFC 7468) at exactly 64.
  • Lax decoders give one byte string many spellings: compare and sign decoded bytes.
  • HTML forms (WHATWG) write space as + and read + as space: raw Base64 in a query string loses its +. Use base64url, or percent-encode with uppercase hex.

Text is an encoding too — hash and sign bytes

é is U+00E9 = C3 A9 in UTF-8 (NFC) or e + U+0301 = 65 CC 81 (NFD): canonically equivalent (UAX #15), different bytes and digests — SP 800-63B-4: a password SHOULD be NFC-normalised before hashing. JSON: sign the exact bytes sent (JWS signs its base64url text, so key order and whitespace never matter) or canonicalise — RFC 8785 JCS: keys by UTF-16 code units, no whitespace.

What everyday artifacts really are

artifactisso
Authorization: Basic dXNlcjpwYXNzBase64 of user:passanyone reads it; RFC 7617: secure only inside TLS
Kubernetes Secret data:Base64etcd stores it unencrypted by default
PEM BEGIN PUBLIC KEYBase64 of DER SubjectPublicKeyInfoencoding of a public value
JWT, App Store JWSTransactionbase64url header.payload.signaturesigned, not encrypted — decoding is not verifying
SRI integrity="sha384-…"Base64(SHA-384(file))trusted because the page carries it; SHA-256/384/512 MUST work
Content-Digest: sha-256=:…:hash (RFC 9530)an on-path attacker swaps it — add TLS or a signature
GitHub X-Hub-Signature-256sha256= + hex HMACcompare in constant time; SHA-1 header is legacy
TOTP 6-digit codeHMAC-SHA1(K, floor(t/30)), truncateda MAC short enough to type

Hashing an identifier is not anonymising it

10-digit phone numbers are only 1010 inputs: hash them all and every digest reverses. EDPB Guidelines 01/2025: anyone who knows the identifier recomputes an unkeyed pseudonym — use a keyed one-way function (a MAC), secret kept apart. Still personal data: pseudonymised (GDPR Art. 4(5)), not anonymous.

MAC vs signature — who can prove what

Both prove integrity and origin. A MAC tag could come from either holder of K: no proof to a third party. A signature comes only from the private-key holder and anyone can check it — non-repudiation (FIPS 186-5: verifiable “by a third party”). RFC 9421 HTTP Message Signatures carries both: hmac-sha256 beside ed25519, ecdsa-p256-sha256, rsa-pss-sha512. A truncated HMAC keeps ≥ half the hash and ≥ 80 bits (RFC 2104).

Encoding vs encryption vs hashing vs signing — figure 2
  • FIPS 186-5 (Feb 2023): RSA, ECDSA (deterministic RFC 6979 too), EdDSA (Ed25519, Ed448); DSA only verifies old signatures; a signing key pair “shall not” do anything else.
  • “Signing = encrypting with the private key” fits only textbook RSA; ECDSA, EdDSA, ML-DSA cannot encrypt. Encryption to a public key proves nothing about who sent it.
  • RSA and ECDSA sign a digest of the message: a collision makes one signature valid for two documents — why MD5 and SHA-1 are dead for signing.

Key derivation — match the KDF to the entropy

inputKDFrule
password, PIN — guessableArgon2id, scrypt, bcrypt, PBKDF2salted and slow: the attacker pays the cost per guess, per user
DH secret, master key — already randomHKDF (RFC 5869)extract concentrates entropy, “cannot amplify” it; info binds the purpose; ≤ 255 × hash length

PBKDF2: U1 = HMAC(P, S ‖i), Uj = HMAC(P, Uj-1), block = U1 ⊕ …⊕UC. Its floors aged: RFC 8018 (salt ≥ 64 bits) and SP 800-132 (2010, revision announced 2023; random salt ≥ 128 bits): ≥ 1 000 iterations; OWASP: 600 000 (SHA-256).

Storing passwords — NIST SP 800-63B-4 (final, Aug 2025)

  • Hash, never encrypt — an encrypted table is one stolen key from every password; OWASP keeps encryption for a password that must be replayed to another system.
  • Salt ≥ 32 bits; a scheme from SP 800-132; cost “as high as practical”, raised over time; SHOULD add a keyed hash with a secret in an HSM or TEE (a pepper).
  • Verify the entire password, never truncate (bcrypt stops at 72 bytes). ≥ 15 characters single-factor, ≥ 8 with MFA, accept ≥ 64; no composition rules; no periodic change; check a blocklist of breached and common passwords; no hints.
  • Hashing on the client does not replace the server’s: whatever the server compares is the password.

Quantum — what changes per job

Encoding vs encryption vs hashing vs signing — figure 3

Dates: NIST IR 8547, still a draft (Nov 2024). Encoding: unaffected. AES ≥ 128, SHA-256, HMAC: PQ category ≥ 1, no transition planned. Public-key jobs fall to Shor: encryption now (recorded today, decrypted later); authentication only when checked — except code a device verifies for years. Detail: post-quantum-crypto.

Traps

  • “It’s encrypted, so nobody changed it” — CBC and CTR without a MAC are malleable; use AEAD.
  • “A key in the binary keeps it secret” — whoever has the app has the key.
  • “A checksum detects tampering” — CRC32c, Adler-32, MD5 catch noise, not attackers (RFC 9530 deprecates them).

Report a problem ·Discuss this folio