NetSecTools

Home / Guides / Encoding vs encryption vs hashing: what is the difference?

Encoding vs encryption vs hashing: what is the difference?

· 8 min read

Encoding, encryption and hashing all turn readable data into something that looks like gibberish. They are often confused, and the confusion causes real vulnerabilities. They solve three different problems.

The short version

Encoding Encryption Hashing
Purpose Represent data in another format Keep data secret Create a fingerprint to compare or verify
Reversible? Yes, by anyone Yes, only with the key No
Needs a key? No Yes No (HMAC adds one)
Protects confidentiality? No Yes No
Examples Base64, URL encoding, hex AES, ChaCha20, RSA SHA-256, SHA-512, bcrypt

Encoding: changing the format

Encoding transforms data so that a system can handle it safely. There is no secret and no security. Anyone can reverse it.

  • Base64 turns binary data into plain text characters, so that it can travel in email, JSON or a web address. It makes data about 33% larger.
  • URL encoding replaces unsafe characters with a percent sign and two hex digits, so a space becomes %20.
  • Hexadecimal shows bytes as readable pairs of characters.
Text:    Hello
Base64:  SGVsbG8=
Hex:     48656c6c6f

With our Base64, URL & Hex Encoder you can encode and decode all three. The key point: Base64 is not encryption. A “protected” value that is only Base64 is visible to everyone.

Encryption: keeping data secret

Encryption scrambles data using an algorithm and a key. Without the key, the result is unreadable. With it, you can restore the original. It protects confidentiality.

There are two families:

  • Symmetric encryption uses one key to encrypt and decrypt. AES is the standard, and it is fast. Example: encrypting a file with a password.
  • Asymmetric encryption uses a pair of keys: a public key to encrypt (or verify) and a private key to decrypt (or sign). RSA and elliptic-curve systems are examples. HTTPS uses it to set up secure connections.

Good modern practice:

  • Use an authenticated mode such as AES-GCM, which also detects tampering. Older modes such as ECB reveal patterns in the data and should not be used.
  • Use a new random nonce (IV) for every message, and never reuse it with the same key.
  • Derive the key from a password with a key derivation function such as PBKDF2, scrypt or Argon2, with a random salt.
  • Do not invent your own algorithm. Use a well-reviewed library.

Our Text Encrypt / Decrypt tool does this in your browser with AES-256-GCM and PBKDF2. If you forget the password, the data cannot be recovered.

Hashing: a fingerprint

A hash function reads data of any size and produces a fixed-size value. The same input always gives the same hash, and a tiny change gives a completely different one. You cannot get the original back from the hash.

Hashing is used for:

  • Verifying integrity, for example comparing a checksum with the one published for a download. See how to verify a file with a checksum.
  • Storing passwords, with the right algorithm (below).
  • Digital signatures and HMAC, which prove that a message was not changed.
  • Finding duplicates and indexing data.

Try it with the Hash Generator.

Passwords: a special case

Passwords are the most common place where the three are mixed up.

  • Never store passwords in clear text or encrypted in a way the application can reverse. If the database leaks, every password leaks with it.
  • Never use a plain fast hash such as MD5 or SHA-256 alone. Attackers can test billions of guesses per second.
  • Use a password hashing function: Argon2id, bcrypt or scrypt. They are deliberately slow, include a unique random salt for each password and have a tunable cost.

Mistakes to avoid

  1. Calling Base64 “encryption”. It hides nothing.
  2. Hashing when you need to recover the data, or encrypting when you only need to compare values.
  3. Using MD5 or SHA-1 for security. Both are broken for collision resistance.
  4. Storing the key next to the data it protects. An encrypted database and its key in the same repository is no protection.
  5. Reusing a nonce with AES-GCM or similar modes.
  6. Using a hash as if it were a secret. A hash of a short or predictable value, such as a phone number, can be reversed by trying all possibilities.
  7. Rolling your own scheme. Combine well-known building blocks, do not design new ones.

Which one do I need?

  • I need to send binary data through a text system. Encoding.
  • I need only the intended recipient to read this. Encryption.
  • I need to know whether this has changed, or to compare without storing the original. Hashing.
  • I need to prove who sent this. A digital signature or an HMAC, which combine hashing with keys.

These ideas also appear inside other formats. A JSON Web Token, for example, is Base64URL-encoded JSON with a hash-based signature. If you are curious, read what a JWT is and how to decode it.