12 min read Applied Cryptography & Data Security Cryptography (7 / 13)
Part 2 — Identity & Cryptography

Lesson 13.07 — Encryption, Hashing & Digital Signatures

Mathematical Foundations of Confidentiality, Integrity, and Authenticity: Symmetric AES-256, Asymmetric Key Pairs, SHA-256, and Digital Signatures

What You Will Master

By the end of this lesson, you will possess a rigorous engineering grasp of the three cryptographic pillars that underpin internet trust and data security:

  • The fundamental cryptographic triad: Confidentiality, Integrity, and Authenticity
  • Symmetric Encryption: Shared secret keys, AES-256, and the Key Distribution Problem
  • Asymmetric Cryptography: Public & Private Key pairs (RSA, ECC) and Hybrid TLS architecture
  • Cryptographic Hashing: Irreversible one-way functions, SHA-256, and the Avalanche Effect
  • General hashing vs. Password Hashing (Argon2id, Bcrypt) and the necessity of Cryptographic Salt
  • Digital Signatures: Signing with private keys, public key verification, and non-repudiation
  • HMAC architecture and API webhook payload verification
  • Hands-on 3-Tab Interactive Cryptography Sandbox (No Quiz)

1 Introduction: How is Digital Information Mathematically Protected?

Imagine transmitting an essential commercial agreement or confidential wire transfer instructions across the public internet to an international counterparty. To execute this transaction safely, you must resolve three distinct technical challenges:

1. Confidentiality

As the file transits intermediate routers and ISP backbones, unauthorized observers must be unable to read the contents. Solution: Encryption.

2. Integrity

The recipient must detect if an adversary altered a single digit or bank account routing number in transit. Solution: Hashing.

3. Authenticity & Non-repudiation

The recipient must prove beyond doubt that the document originated from your authorized identity, and you cannot later dispute having sent it. Solution: Digital Signatures.

The overarching science enabling all three assurances is Cryptography. Cryptography utilizes sophisticated mathematics and algorithmic keys to secure digital assets, establishing zero-trust communications over inherently untrusted networks.

2 What is Encryption & How Does It Work?

Encryption is the reversible cryptographic transformation of human-readable information (Plaintext) into an unintelligible encoded form (Ciphertext) using a specialized cipher algorithm and a cryptographic key.

To any eavesdropper lacking the appropriate key, the ciphertext appears as pseudorandom noise. Only an authorized party possessing the corresponding cryptographic key can reverse the process (Decryption) to restore the original plaintext.

The Two Foundations: Symmetric vs. Asymmetric Encryption

Based on how keys are managed, modern cryptography is bifurcated into two foundational architectures:

Architecture 1: Symmetric Encryption

Single Shared Secret Key

The exact same secret key is utilized to both encrypt and decrypt the payload. Both endpoints must possess this identical shared secret.

Plaintext + SecretKey_A => Ciphertext
Ciphertext + SecretKey_A => Plaintext

Standards: AES (Advanced Encryption Standard - AES-128, AES-256) and ChaCha20.

Strengths: Hardware-accelerated and exceptionally fast. Ideal for multi-gigabyte disk encryption and streaming media.

Limitation: The Key Distribution Problem—how do two unacquainted parties safely transmit the secret key over the public internet?

Architecture 2: Asymmetric Cryptography

Public & Private Key Pairs

Employs a mathematically linked pair: a publicly broadcast Public Key and a strictly guarded Private Key.

Plaintext + Bob_PublicKey => Ciphertext
Ciphertext + Bob_PrivateKey => Plaintext

Standards: RSA (2048/4096-bit) and ECC (Elliptic Curve Cryptography - Curve25519, secp256r1).

Strengths: Solves key distribution; the private key never leaves the owner's hardware.

Limitation: Computationally demanding; roughly 1,000 times slower than symmetric AES.

Real-World Engineering: Hybrid Cryptography (HTTPS / TLS 1.3)

Production systems do not choose one over the other; they combine both into an optimal Hybrid Encryption pipeline:

1. During initial connection setup, client and server execute an asymmetric handshake (ECDH) to verify identities and securely negotiate an ephemeral symmetric session key.
2. Once established, all subsequent high-throughput web traffic is encrypted with ultra-fast symmetric AES-256-GCM.

3 What is Hashing & Why is it Strictly One-Way?

Cryptographic Hashing is a deterministic, irreversible one-way mathematical function that maps input data of arbitrary size (from a single character to a multi-gigabyte ISO image) into a fixed-length hexadecimal digest (Hash Value / Digest).

1. Irreversible (Preimage Resistance)

Computing the digest from the input occurs in milliseconds. However, mathematically reversing the hash to deduce the original input is impossible; there is no "decryption key."

2. Fixed Length Output

Regardless of whether the input is 10 bytes or 10 terabytes, the output of SHA-256 is invariably 256 bits (64 hexadecimal characters).

3. The Avalanche Effect

Altering even a single bit or comma in the source document causes more than 50% of the resulting digest bits to scramble unpredictably.

4. Collision Resistance

It is computationally infeasible to discover two distinct input messages $M_1 e M_2$ that produce the identical hash digest ($2^{128}$ operations required).

Engineering Rule: Never Use Standard SHA-256 for Passwords!

Standard hash functions like SHA-256 were designed for speed. A modern GPU rig evaluates billions of SHA-256 calculations per second, rendering offline dictionary and brute-force attacks trivial.

Password storage demands memory-hard, computationally expensive algorithms: specifically Argon2id (winner of the Password Hashing Competition) or Bcrypt. Furthermore, each password must be combined with a unique, cryptographically random Salt to defeat precomputed rainbow tables.

4 What are Digital Signatures & How Do They Work?

A Digital Signature is a cryptographic mechanism providing Authenticity (identity verification), Integrity (tamper detection), and Non-repudiation (binding legal provenance).

Unlike ink signatures, which can be forged or severed from contract terms, a digital signature is mathematically bound to the exact bitstream of the document. If a single punctuation mark is altered after signing, the mathematical signature instantly fails verification.

The 3 Stages of Digital Signature Generation & Verification

1
Stage 1: Document Digest Generation (Hashing) The source file is hashed via SHA-256 to create a compact, unique 256-bit digest.
2
Stage 2: Asymmetric Encryption (Signing) The signer encrypts the digest with their strictly protected Private Key. This encrypted digest constitutes the Digital Signature, which is bundled with the document.
3
Stage 3: Public Key Verification (Verification) The recipient decrypts the signature using the signer's Public Key to reveal the expected digest, while simultaneously computing a fresh SHA-256 hash of the received document. If both hashes match identically, authenticity and integrity are proven.

Recognized industry standards: RSA-PSS, ECDSA, and Ed25519.

5 Encryption vs. Hashing vs. Digital Signatures

These three cryptographic primitives are not interchangeable; they fulfill discrete responsibilities in a defense-in-depth architecture:

Dimension Encryption Hashing Digital Signatures
Primary Purpose Data Confidentiality (Secrecy) Data Integrity (Tamper Detection) Authenticity & Non-repudiation
Mathematical Direction Reversible (Decryptable with Key) One-Way (Irreversible) Signature Generation & Verification
Key Architecture Secret Key (Symmetric) or Key Pair Unkeyed (except HMAC) Private Key (Sign) + Public Key (Verify)
Provides Confidentiality? YES (Conceals plaintext) NO (Does not conceal data) NO (Signed data remains readable)
Modern Algorithms AES-256, ChaCha20 SHA-256, Argon2id, BLAKE3 Ed25519, RSA-PSS, ECDSA

What is HMAC (Hash-based Message Authentication Code)?

HMAC provides symmetric message authentication by combining a shared secret key with a cryptographic hash (such as SHA-256). It is significantly faster than asymmetric digital signatures and is standard for securing API webhooks (e.g., Stripe, GitHub) and verifying JWT session signatures.

6 5 Critical Cryptographic Mistakes in Production Systems

Cryptography is mathematically unforgiving; minor implementation shortcuts routinely cause catastrophic systemic failures:

1. "Rolling Your Own Crypto"

Never attempt to design proprietary encryption algorithms or write custom mathematical cipher implementations. Always rely on battle-tested, peer-reviewed libraries (e.g., Web Crypto API, OpenSSL, Libsodium).

2. Utilizing Broken Legacy Algorithms (MD5, SHA-1, DES)

MD5 and SHA-1 suffer from demonstrated mathematical collision vulnerabilities. Modern standards mandate SHA-256 or SHA-3.

3. Hardcoding Keys in Source Repositories

Committing private keys or symmetric encryption tokens into Git repositories permanently invalidates the security boundary. Employ secure Key Management Services (AWS KMS, HashiCorp Vault).

4. Conflating Base64 Encoding with Encryption

Base64 is an open data serialization format, not an encryption cipher. It possesses zero secret keys and can be decoded instantaneously by any observer.

Interactive Lab

Interactive Cryptography Sandbox

NO QUIZ · 3 TABS

Experiment with symmetric AES encryption/decryption, observe the SHA-256 Avalanche Effect in real time, and simulate digital signature tamper-detection.

Cryptographic Result (AES-GCM): ENCRYPTED
Ciphertext (Hex format):

9f4b7a2e1d08c5f3e9a1b8c2d4e6f7015a8b9c0d

Decrypted Plaintext:

Transfer $5,000 to Account #8821

// AES-256 Auth Tag Check:

Authentication tag valid. Message confidentiality and integrity confirmed.

8 Lesson Summary: Core Takeaways

1. The 3 Cryptographic Pillars

Encryption delivers confidentiality, Hashing guarantees integrity, and Digital Signatures establish authenticity and non-repudiation.

2. Symmetric vs. Asymmetric

Symmetric (AES) is exceptionally fast for bulk data; Asymmetric (RSA/ECC) resolves key distribution via public/private key pairs.

3. Irreversible Hashing

Cryptographic hashes are one-way functions where single-bit changes trigger the dramatic Avalanche Effect.

4. Password Hashing Rules

Fast general-purpose hashes are unsuitable for passwords; memory-hard Argon2id or Bcrypt with cryptographic salt is mandatory.

5. Digital Signatures

Signing document digests with private keys enables universal public-key verification without disclosing private secrets.

6. Standard Cryptographic Libraries

Never invent custom encryption algorithms; always rely on audited, standardized cryptographic primitives.

Authoritative References:

NIST SP 800-175B (Guideline for Using Cryptographic Standards), FIPS 197 (Advanced Encryption Standard - AES), FIPS 180-4 (Secure Hash Standard - SHA), FIPS 186-5 (Digital Signature Standard - DSS), and OWASP Cryptographic Storage Cheat Sheet.