CYBER SECURITY • CRYPTOGRAPHY BASICS

Encryption, Hashing & Encoding — Distinguish encryption, hashing, and encoding (conceptual)

Understanding the three fundamental data transformations that underpin modern information security.

Historical Context & Motivation

The need to transform data for confidentiality, integrity, and interoperability is as old as communication itself. Ancient civilizations employed rudimentary ciphers to conceal military dispatches, while merchants devised encoding schemes to represent quantities in compact formats for trade records. As information systems evolved from papyrus scrolls to digital networks, the distinction between encryption, hashing, and encoding crystallized into three conceptually separate operations, each solving a fundamentally different problem. Conflating these three transformations is one of the most common mistakes in security engineering, leading to vulnerabilities that range from exposed passwords to broken authentication protocols.

~50 BCE
Caesar Cipher
Julius Caesar employed a simple substitution cipher — shifting each letter by a fixed number — to protect military correspondence. This is one of the earliest documented examples of encryption for confidentiality.
1949
Shannon's Information Theory
Claude Shannon published "Communication Theory of Secrecy Systems," formalizing the mathematical foundations of cryptography and introducing concepts like perfect secrecy and entropy in the context of ciphers.
1976
Diffie-Hellman & Public-Key Cryptography
Whitfield Diffie and Martin Hellman proposed asymmetric key exchange, decoupling encryption keys from decryption keys and enabling secure communication without a pre-shared secret.
1992
MD5 & the Rise of Hash Functions
Ronald Rivest published MD5, which became the de facto standard for data integrity checks and password storage — though its collision vulnerabilities would later be exposed.
2000s
Base64, UTF-8 & Modern Encoding Standards
The proliferation of web APIs and email protocols cemented encoding schemes like Base64 and UTF-8 as essential — yet explicitly non-cryptographic — data representation tools.

The central question this lesson addresses is deceptively simple: when you transform a piece of data, what guarantees does that transformation provide? Encryption provides confidentiality through reversible, key-dependent transformation. Hashing provides integrity through irreversible, deterministic fingerprinting. Encoding provides compatibility through reversible, keyless format conversion. Misidentifying which operation you need — or assuming one provides the guarantees of another — is a root cause of real-world security breaches.

Core Principles & Definitions

Each of the three transformations can be characterized along several orthogonal axes: reversibility, key dependence, security purpose, and output determinism. Understanding these axes prevents the confusion that leads to dangerous implementation choices, such as using Base64 encoding in place of encryption or storing passwords with reversible encryption rather than hashing.

1

Encryption

A reversible transformation that converts plaintext into ciphertext using a key. Only parties possessing the correct key can recover the original data. The primary goal is confidentiality.
2

Hashing

A one-way function that maps arbitrary-length input to a fixed-length digest. No key is involved; the same input always produces the same output. The primary goal is integrity verification.
3

Encoding

A reversible, keyless format conversion that translates data from one representation to another. Anyone with knowledge of the scheme can decode the data. The primary goal is data compatibility across systems.
4

Reversibility Spectrum

Encoding is freely reversible by anyone. Encryption is reversible only with the correct key. Hashing is computationally irreversible — you cannot derive the input from the output in polynomial time for a well-designed hash function.
5

Security Intent

Encryption and hashing are security primitives designed to withstand adversarial attacks. Encoding provides zero security guarantees and should never be used as a substitute for encryption or hashing.
KEY TAKEAWAY
Think of a safe with a combination lock as encryption: only someone with the combination (key) can open it and retrieve the contents. A fingerprint is like a hash: it uniquely identifies a person, but you cannot reconstruct the person from the fingerprint. A language translation is like encoding: it changes the representation so that a different audience can understand the same message — no secret is involved.

Visual Explanation — Data Transformation Flows

The three rows illustrate the fundamental flow of each transformation. Encryption requires a key for both directions. Hashing is a one-way street — the digest cannot be reversed. Encoding is freely reversible by anyone without any secret.

The diagram above captures the most critical distinction visually. Notice that encryption and encoding both produce outputs from which you can recover the original data, but they differ fundamentally in the requirement for a secret key. Encoding uses a publicly known scheme — there is no secret, and therefore no confidentiality. Hashing, by contrast, is designed so that the transformation is computationally infeasible to invert; the information is deliberately destroyed in the mapping from an arbitrary-length input to a fixed-length output. This property, known as pre-image resistance, is what makes hash functions suitable for password storage and digital signatures, where recovering the original input would constitute a security failure.

How Each Transformation Works

Encryption Mechanics

Encryption algorithms take a plaintext message M and a key K, producing a ciphertext C through a deterministic function. The core requirement is that an efficient inverse function exists — the decryption function — but only when the correct key is supplied. In symmetric encryption, the same key is used for both operations. In asymmetric encryption, a public key encrypts and a mathematically related private key decrypts.

SYMMETRIC ENCRYPTION
C = E(K, M) and M = D(K, C)
E is the encryption function, D is the decryption function, K is the shared secret key, M is the plaintext message, and C is the ciphertext. D(K, E(K, M)) = M must hold for correctness.
ASYMMETRIC ENCRYPTION
C = E(K_pub, M) and M = D(K_priv, C)
Kpub is the public key; Kpriv is the private key. The security rests on the computational hardness of deriving Kpriv from Kpub (e.g., integer factorization for RSA or the discrete logarithm problem).

Hashing Mechanics

A cryptographic hash function H maps an input of arbitrary length to a fixed-length output, called a digest or hash value. Because the output space is finite (e.g., 256 bits for SHA-256) while the input space is infinite, collisions must exist by the pigeonhole principle — but a well-designed hash function makes finding them computationally infeasible.

HASH FUNCTION
h = H(M), where |h| is fixed (e.g., 256 bits)
Three essential properties: pre-image resistance (given h, infeasible to find M), second pre-image resistance (given M₁, infeasible to find M₂ ≠ M₁ with H(M₁) = H(M₂)), and collision resistance (infeasible to find any M₁ ≠ M₂ with equal hashes).

Encoding Mechanics

Encoding is a deterministic, publicly known, and freely invertible mapping. Base64, for instance, takes each group of 3 bytes (24 bits) and maps them to 4 characters from a 64-character alphabet. URL encoding replaces unsafe characters with percent-encoded equivalents (e.g., a space becomes %20). UTF-8 encodes Unicode code points into 1–4 byte sequences. In every case, no secret is involved — the transformation is entirely defined by the specification, and anyone can reverse it. Encoding solves a data representation problem, not a security problem.

Detailed Classification & Properties

This property matrix provides a side-by-side comparison of the six most important characteristics across all three transformations. The key differentiator is the intersection of reversibility and key dependence.

Several nuances deserve closer attention. While both hashing and encryption are deterministic in the basic sense (the same inputs yield the same outputs), modern encryption schemes typically employ an initialization vector (IV) or nonce to ensure that encrypting the same plaintext twice with the same key yields different ciphertexts — a property called semantic security. Similarly, password hashing functions like bcrypt and Argon2 prepend a random salt to each input before hashing, so that two users with the same password produce different digests. These mechanisms add controlled randomness at the input stage while keeping the underlying function deterministic.

⚠️ Common Misconception
Base64 is sometimes mistakenly called "Base64 encryption." This is incorrect and dangerous: Base64 provides zero confidentiality. Any tool can decode Base64 instantly. If you see credentials stored in Base64 in a configuration file or API call, treat them as plaintext.

Worked Example — Identifying the Right Transformation

Consider the following scenario: a web application needs to store user passwords, transmit binary image data over a JSON API, and send confidential messages between two servers. We must select the correct transformation for each requirement.

Selecting Encryption, Hashing, or Encoding
1
Step 1 — Password StorageRequirement: verify that a user-provided password matches the stored credential without ever storing or recovering the original password. Since we need a one-way, fixed-length representation and we must never be able to reverse the process, the correct transformation is hashing — specifically, a password hashing function with a per-user salt (e.g., bcrypt, Argon2).
Answer: Hashing (with salt)
2
Step 2 — Binary Image in JSONRequirement: embed raw binary image bytes inside a JSON string, which only supports text characters. No secret needs to be kept — the image is visible to anyone with access to the API response. We need a format conversion from binary to a text-safe representation.
Answer: Encoding (Base64)
3
Step 3 — Confidential Server-to-Server CommunicationRequirement: ensure that if an adversary intercepts the network traffic, they cannot read the message content. We need the original message to be recoverable by the intended recipient (reversibility) but only by someone possessing the correct credentials (key dependence). This demands encryption — typically TLS for the transport layer, which uses asymmetric encryption for key exchange followed by symmetric encryption (e.g., AES-256-GCM) for bulk data.
Answer: Encryption (AES via TLS)
4
Step 4 — Verification CheckLet's verify our choices against the property axes. Password storage: we want irreversibility ✓ (hashing), no key management burden ✓, and the ability to compare digests for authentication ✓. Image embedding: we want reversibility ✓ (encoding), no secret ✓, and text-safe output ✓. Confidential messaging: we want reversibility with authorization ✓ (encryption), confidentiality ✓, and key-based access control ✓. All three choices align correctly with the requirements.
All selections verified against the reversibility / key-dependence / security-purpose framework.

Strengths, Limitations & Common Pitfalls

Comparative overview of strengths, limitations, pitfalls, and examples
CriterionEncryptionHashingEncoding
StrengthProvides confidentiality; mathematically rigorous security proofs available for many schemes.Irreversibility enables safe credential storage; collision resistance supports digital signatures.Simple, fast, universal; ensures interoperability across heterogeneous systems.
LimitationKey management complexity; performance overhead for large data; vulnerable if keys are compromised.Susceptible to brute-force / rainbow table attacks if used without salt; collisions eventually found for older algorithms (MD5, SHA-1).Provides zero security; often increases data size (Base64 adds ~33% overhead).
Common PitfallUsing ECB mode, reusing IVs, or using encryption for password storage (reversibility defeats the purpose).Using unsalted hashes for passwords, or relying on fast hashes (SHA-256) instead of password-specific functions (bcrypt).Treating Base64 or URL-encoding as a security measure; calling it "encryption."
Example AlgorithmsAES, ChaCha20, RSA, ECCSHA-256, SHA-3, bcrypt, Argon2, BLAKE3Base64, UTF-8, URL encoding, Hex encoding
KEY TAKEAWAY
A useful mental model is to think of these transformations as tools in a toolbox: a lock (encryption) protects access, a wax seal (hashing) proves authenticity and detects tampering, and a translator (encoding) makes content understandable to a different audience. Using a translator when you need a lock is a category error that attackers exploit routinely — the 2012 LinkedIn breach, for example, exposed millions of unsalted SHA-1 password hashes that were trivially reversed.

Connection to Advanced Cryptographic Theory

The conceptual distinctions established here form the foundation for more advanced constructions in modern cryptography. Understanding what each primitive provides — and what it does not — is prerequisite knowledge for topics like authenticated encryption, HMAC (Hash-based Message Authentication Codes), digital signatures, and key derivation functions. Each of these advanced primitives combines the guarantees of basic encryption and hashing in specific ways to achieve composite security goals.

From basic primitives to advanced constructions
Basic ConceptAdvanced ExtensionWhat It Adds
Encryption (confidentiality only)Authenticated Encryption (AES-GCM, ChaCha20-Poly1305)Combines encryption with an integrity tag, providing both confidentiality and tamper detection in a single operation.
Hashing (integrity only)HMAC (e.g., HMAC-SHA256)Keyed hash that provides authentication — only parties with the secret key can produce or verify a valid MAC, preventing forgery.
Hashing (verification)Digital Signatures (RSA-PSS, ECDSA)Hash the message, then encrypt the digest with a private key. Provides non-repudiation — the signer cannot deny having signed.
Hashing (password storage)Key Derivation Functions (PBKDF2, Argon2)Adds deliberate computational cost (memory-hard or time-hard) to resist brute-force and hardware-accelerated attacks.

The overarching trajectory in cryptographic design is toward composing primitives correctly rather than inventing new ones. The infamous "encrypt-then-MAC" versus "MAC-then-encrypt" debate illustrates how even well-understood primitives can be combined insecurely if the composition order is wrong. Authenticated encryption modes like GCM and CCM were developed precisely to eliminate this class of errors by packaging encryption and integrity into a single, misuse-resistant interface. As you advance in cryptography, you will find that nearly every construction can be decomposed back into the three atomic operations introduced in this lesson.

Practice Problems

PROBLEM 1CONCEPTUAL
A colleague proposes storing API tokens by Base64-encoding them before writing to a database, arguing that this prevents attackers from reading the tokens if the database is breached. Identify the flaw in this reasoning and explain which transformation should be used instead.
PROBLEM 2BASIC CALCULATION
A SHA-256 hash produces a digest of 256 bits. If you hash the 5-character ASCII string Hello (40 bits of input), what is the length of the output in bytes? What happens to the output length if the input is a 1 GB file?
PROBLEM 3INTERMEDIATE
An application encrypts user passwords with AES-256 and stores the ciphertext alongside the encryption key (in the same database table) to verify login credentials. Identify at least two security problems with this design and propose a better approach.
PROBLEM 4APPLIED
You are designing a software update distribution system. The update server hosts binary packages that clients download over HTTPS. You want to ensure that (a) the download is not tampered with in transit, (b) the package file has not been corrupted on the mirror server, and (c) only authorized servers can publish updates. For each requirement, state which transformation(s) you would use and why.
PROBLEM 5CRITICAL THINKING
Consider the following claim: "Because both hashing and encoding are keyless operations, the only real distinction that matters in security engineering is between encryption (keyed) and everything else (keyless)." Construct a rigorous argument against this claim, drawing on the properties of each transformation.

Lesson Summary

This lesson established the fundamental distinctions among three data transformations that underpin information security. Encryption is a reversible, key-dependent transformation whose primary purpose is confidentiality — it ensures that only authorized parties holding the correct key can recover the original data. Hashing is a one-way, keyless function that maps arbitrary-length input to a fixed-length digest, providing integrity verification and safe credential storage through properties like pre-image resistance and collision resistance. Encoding is a freely reversible, keyless format conversion that solves data compatibility problems but provides zero security guarantees.

The two critical axes for classification are reversibility (freely reversible, reversible with key, or irreversible) and key dependence (keyed or keyless). Confusing these transformations leads to real-world vulnerabilities — from storing passwords with reversible encryption to trusting Base64 for confidentiality. Advanced cryptographic constructions such as authenticated encryption, HMAC, and digital signatures compose these basic primitives to achieve composite security goals, making precise understanding of each primitive essential for secure system design.

Varsity Tutors • Cyber Security • Encryption, Hashing & Encoding