Week 10

Security Mindset

Threat Modeling Basics

Common Backend Vulnerabilities

Handling Sensitive Data

Hashing vs. Encryption

How to Store Passwords

Authentication & Authorization

Spring Security

Spring Security JWT authentication

Practice

Assignment

Backend Track

Introduction

In an era of constant cyber threats and data breaches, robust application security relies on cryptographic techniques and tools to ensure both confidentiality and integrity in compliance with regulatory standards. People often mixing the terms "hashing" and "encryption" when talking about cryptography, but they are fundamentally different and serve distinct purposes. Choosing the wrong one can lead to a major security vulnerability.

Encryption

Data encryption is a security process that converts readable data (plain-text) into an unreadable code, known as cipher-text, using a specific algorithm and a secret key. This ensures that only authorized individuals with the correct key can decipher the information, protecting sensitive data from unauthorized access, both when it is being stored and when it is being transmitted.

How does it work

Data encryption works by applying a mathematical algorithm, along with a secret key, to transform the original plaintext data into an unreadable cipher-text. The same key is then used to then reverse the process, “decrypting the cipher-text,” and revealing the original plaintext. Without the correct key, the cipher-text remains unintelligible and thus inaccessible to unauthorized individuals.

Types of Data Encryption

There are two broad categories of data encryption: symmetric and asymmetric encryption. Both have their own strengths and weaknesses and are used for different purposes.

1. Symmetric Encryption

Symmetric encryption uses the same key for both encryption and decryption processes. It’s quicker and less demanding on resources, ideal for encrypting large data volumes.

Watch: Symmetric encryption explainer

https://www.youtube.com/watch?v=r3JX6sLA9XI

2. Asymmetric Encryption

Also known as public-key encryption, asymmetric encryption uses two keys: one for encryption and another for decryption. The data is encrypted with the public key, and its decryption is facilitated by the private key. This process eliminates the need to share keys, thereby increasing security, but it’s more demanding on resources than symmetric encryption.

Watch: Asymmetric encryption explainer

http://www.youtube.com/watch?v=9ukUYMcEh3Y

<aside> 💭

The type of encryption chosen depends on the specific needs and resources of the situation.

</aside>

Common Data Encryption Algorithms

Data encryption algorithms convert plaintext data into ciphertext, ensuring data confidentiality and integrity. Each method has a compelling use case and times when it is not sufficient. Before implementing one into your business, consider how each might benefit or hinder your data privacy goals.

Benefits of Data Encryption

Challenges in Implementing Data Encryption

Implementing data encryption involves three main challenges. First, complex key management is required to securely generate, store, and rotate cryptographic keys, as improper handling can make the encryption worthless. Second, encryption can create a performance impact, slowing down systems and forcing a trade-off between security and application speed. Finally, organizations face the difficulty of ensuring compliance with diverse and evolving industry and regional data protection regulations.

Hashing

Hashing is a one-way cryptographic process that transforms any input data into a fixed-size string of characters, known as a hash value or digest. Unlike encryption, which is a two-way process designed to be reversed (decrypted), hashing is irreversible. You cannot retrieve the original data from its hash. The primary purpose of hashing is not to hide data, but to verify its integrity and authenticity. By comparing the hash of a piece of data at two different points in time, you can instantly know if it has been altered in any way.

How does it work?

Hashing works by feeding data of any size—from a single word to a large file—into a mathematical hash function. This function processes the input and produces a unique, fixed-length output. For example, the SHA-256 algorithm will always produce a 256-bit (64-character) hash, regardless of whether the input is "hello" or the entire text of a book.

The process is deterministic, meaning the same input will always generate the exact same hash value. However, a tiny change in the input (like changing a single letter) will produce a completely different hash.

Watch: Intro to hashing

https://www.youtube.com/watch?v=QZY3IjFBtFY

Key Properties of a Good Hash Function

A secure hashing algorithm is built on several key principles:

Common Hashing Algorithms

Just like with encryption, different hashing algorithms have been developed over the years, with varying levels of security.

Where is Hashing Used?

Hashing is a workhorse in modern computing and is used in many scenarios:

Encryption vs. Hashing: A Quick Summary

Feature Encryption Hashing
Purpose Confidentiality (to keep data secret) Integrity (to verify data hasn't changed)
Function Type Two-way (Encrypt & Decrypt) One-way (Irreversible)
Output Variable length (related to input) Fixed length
Key Requires a secret key to reverse No key is used
Primary Use Case Securing data in transit and at rest Storing passwords, verifying file integrity

Now that we understand the fundamental difference and know that hashing is the correct tool for passwords, let's explore how to do it correctly.

Watch: YouTube doesn’t know your password

This short video explains one of the concepts we learned in this chapter - Hashing

https://www.youtube.com/watch?v=yoMOAIzBSpY

Extra resources

Videos


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❤️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.