Encoding, encryption and hashing
Three different purposes
Encoding changes representation so data can be stored or transferred. Encryption protects confidentiality using a key. A cryptographic hash produces a digest (a compact fingerprint of data) for comparisons. For example, Base64 represents the ASCII text abc as YWJj; anyone can decode it without a secret.
Plaintext and ciphertext
Plaintext is the original data, which may be text or binary. Encryption produces ciphertext; authorized decryption recovers the plaintext with the appropriate key. Use authenticated encryption from established libraries so unintended or unauthorized changes can also be detected. Encryption alone does not necessarily authenticate data.
Compare a digest
SHA-256 produces a 256-bit digest, commonly displayed as 64 hexadecimal characters. For exactly the three bytes abc, without a newline, the SHA-256 digest is ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad. The same bytes give the same digest; changing even one byte generally changes it. Different inputs can in principle share a digest, but a secure hash is designed to make finding such collisions infeasible.
What a hash cannot prove
A bookstore receives a catalog and a digest over the same untrusted channel. Matching the two does not establish who supplied the catalog: both could have changed. Compare with a digest obtained through a trusted channel, or verify a trusted signature. A hash has no general inverse, but an attacker can guess a low-entropy input and compare hashes. Never use plain SHA-256 alone for password storage; dedicated password hashing is covered later.
Practice: choose a transformation
A document must fit a text-only field, a backup must stay private, and a downloaded catalog needs comparison with a trusted fingerprint. Choose a different transformation for each, and explain which information must remain secret. Next, learn how encryption keys are organized.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Encoding, encryption and hashing — knowledge check
Apply the cryptographic concept to fictional scenarios.
A text-only transport rejects binary data. What should you use?
A backup must remain unreadable without authorized key access. Which protects this goal?
What happens when the same exact bytes are hashed twice with SHA-256?
The file and matching digest arrive through one untrusted channel. What is missing?
Why is plain SHA-256 alone unsuitable for password storage?