Skip to content

How Encryption Works: A Practical Guide to Data Encryption Best Practices

How Encryption Works Protecting Your Digital Information - Softwarecosmos.com

Encryption turns readable data into ciphertext using a key, and the key is what makes it reversible. Symmetric algorithms like AES use one key and handle the bulk of your data. Asymmetric algorithms like RSA and ECC use a key pair and solve the problem of getting that shared key to the other side safely. TLS combines both, which is why every HTTPS connection uses asymmetric math briefly and symmetric math for everything after. Hashing is not encryption, because it does not reverse at all, and using a fast hash for passwords is one of the most common mistakes in production systems. Get the algorithm right, then spend your real effort on key management, because that is where encryption actually fails.

Most people learn encryption as a formula. Plaintext plus key equals ciphertext. That is accurate and almost useless.

The part that matters in practice is what happens around the key. Where is it stored? Who can read it? How long does it live? What happens when someone leaves the company and their laptop still holds a copy of the database backup?

So let me start with the mechanics, keep them tight, and then spend the bulk of this piece on the decisions that actually break systems.

How Encryption Works

Encryption maps readable data to unreadable data using a mathematical function and a secret. Decryption reverses it with the correct key.

Two properties matter more than anything else:

  • Confidentiality. Without the key, the ciphertext should reveal nothing about the plaintext beyond its approximate length.
  • Reversibility. The original data is recoverable by someone holding the key. This is what separates encryption from hashing.

Everything else, from block size to key length to mode of operation, exists to make those two properties hold up under attack.

Symmetric vs Asymmetric Encryption

There are two families, and they solve different problems.

Symmetric encryption

Symmetric vs Asymmetric Encryption - Softwarecosmos.com

One key encrypts and decrypts. It is fast, cheap, and used for almost all bulk data.

The standard is AES. Per FIPS 197, the AES algorithm uses keys of 128, 192, or 256 bits and encrypts data in blocks of 128 bits. AES-128 runs 10 rounds, AES-192 runs 12, and AES-256 runs 14. More rounds and a longer key mean more work for an attacker.

The weakness is distribution. If two parties share one key, how do they exchange it without someone listening? That question is why the second family exists.

Asymmetric encryption

Asymmetric Encryption - Softwarecosmos.com

Two mathematically linked keys: a public one anyone can have, and a private one you never share. Encrypt with the public key and only the private key can decrypt. Sign with the private key and anyone holding the public key can verify it came from you.

RSA and elliptic curve cryptography are the two you will meet. RSA relies on the difficulty of factoring large numbers. ECC relies on the elliptic curve discrete log problem, which reaches equivalent security with much shorter keys, and that is why it dominates on mobile and embedded hardware. If you want a deeper comparison, ECC vs RSA in SSL and TLS covers key sizes and performance tradeoffs.

Asymmetric crypto is slow. You would not encrypt a database with it. You use it to agree on a symmetric key, then switch.

How TLS Uses Both: Hybrid Encryption

Every HTTPS connection is a demonstration of how the two families cooperate.

  1. The client connects and the two sides negotiate parameters.
  2. They perform a key exchange using asymmetric or elliptic curve math.
  3. Both sides derive the same symmetric session key.
  4. All application data then flows encrypted with that fast symmetric key.

TLS 1.3 changed something important here. Per RFC 8446, static RSA and Diffie-Hellman cipher suites were removed, and all public-key based key exchange mechanisms now provide forward secrecy.

Forward secrecy is not jargon. It means each session gets its own ephemeral key, so stealing a server’s long-term private key tomorrow does not let an attacker decrypt traffic they recorded last year. That single change removed a whole class of dragnet decryption, which is why old TLS versions are worth retiring even when nobody has broken them outright.

The same principle shows up in VPNs. A VPN tunnels your traffic through an encrypted channel, and the protocol determines how keys are negotiated and what gets protected. The different types of VPN encryption protocols covers where WireGuard, OpenVPN and IPSec differ on this, and the difference is mostly in handshake design rather than cipher choice.

Hashing Is Not Encryption

Hashing Is Not Encryption - Softwarecosmos.com

This confusion causes real breaches, so it is worth being blunt about it.

Hashing runs data through a one-way function and produces a fixed-length output. There is no key and no decryption. You can verify that a password matches a stored hash, and you cannot recover the password from it.

That makes hashing the correct tool for passwords and the wrong tool for anything you need to read back later.

The critical detail is speed. Fast hashes like SHA-256 are built for throughput, which makes them terrible for passwords, because an attacker with a GPU can try billions of guesses per second. OWASP’s Password Storage Cheat Sheet is direct on both points: passwords should never be stored in plain text, and fast hashes such as SHA-256 are not suitable for password storage.

What they recommend instead, in order of preference:

  • Argon2id at a minimum of 19 MiB of memory, an iteration count of 2, and 1 degree of parallelism. Other accepted configurations trade memory for passes, such as 46 MiB with 1 pass, or 7 MiB with 5 passes.
  • scrypt if Argon2id is unavailable, with a minimum CPU and memory cost parameter of 2^17, block size 8, and parallelization 1.
  • bcrypt for legacy systems, with a work factor of 10 or more and a maximum password length of 72 bytes.
  • PBKDF2 when FIPS 140 compliance is required, at 600,000 iterations or more with HMAC-SHA-256.

Two additions to that. A salt is a unique random value per password, which stops an attacker from cracking one hash and reusing the result across the whole table. A pepper is a shared secret added on top, and it must be stored separately from the database, ideally in a secrets vault or an HSM. OWASP notes the cost of a pepper: if it is ever compromised, changing it requires forcing every affected user to reset their password, because you cannot re-pepper a hash without the original password.

For everything else, you still have options beyond plain encryption. Tokenization and encryption solve different problems, and the difference matters when you handle payment data: a token has no mathematical relationship to the original value, so a leaked token vault does not hand over the numbers.

The Three States of Data

Encryption advice that ignores context is useless, because data needs different protection in each state.

StateWhat it meansWhat protects it
At restStored on disk, in a database, in object storage, on a backup tapeFull disk encryption, database-level encryption, encrypted object storage, key management service
In transitMoving across a network between client, server, service and databaseTLS 1.2 or 1.3, certificate validation, mutual TLS for service to service
In useLoaded in memory while being processedConfidential computing, secure enclaves, memory encryption, and honestly, limits on what you should process at all

In transit and at rest are table stakes in 2026. In use is where the interesting work is happening, because data in memory is exposed to the operating system, to hypervisors, and to anyone with the right privileges on the host.

One practical note. Disk encryption protects a stolen laptop. It does nothing against an attacker who reaches your application and queries the database through it, because your application decrypts transparently. That is why application-level encryption of specific fields still matters even when your storage layer claims to be encrypted.

Key Management Is the Whole Game

Here is where encryption projects fail. The algorithm is almost never the weak point. The key handling is.

NIST’s key management guidance, SP 800-57 Part 1, frames this as a lifecycle: generation, distribution, storage, use, rotation, archiving, and destruction. Every phase has failure modes, and most of them are operational rather than mathematical.

The four rules that prevent most disasters

  • Never hard-code a key in source code. It ends up in a git history that outlives the employee who wrote it.
  • Never commit keys to version control. Rotating a key that leaked into a public repo is not optional, and it is expensive.
  • Keep keys out of environment variables where you can. OWASP flags this specifically, because env vars leak through debug output and through files like /proc/self/environ.
  • Store keys separately from the data they protect. If the ciphertext lives in a database, the key should live somewhere else, so that one compromised system does not hand over both halves.

That last rule is the logic behind envelope encryption. You encrypt the data with a data key, then encrypt that data key with a separate master key held in a key management service. AWS documents the pattern plainly: encrypt plaintext with a data key, then encrypt the data key under another key. The benefit is that you rotate the master key without re-encrypting terabytes of data, and the master key never leaves the HSM.

Rotation is a schedule, not a reflex

OWASP lists the triggers clearly. Rotate a key when it is known or suspected to be compromised, after the cryptoperiod expires, before you hit the usage limits of the cipher mode, or when the algorithm’s security posture changes.

That last trigger is why nobody should be running 3DES or SHA-1 in new systems. NIST’s transition guidance in SP 800-131A deprecated Triple DES and disallowed it for most applications after December 31, 2023. If you are still finding TDEA cipher suites in a scan, that is a task, not a footnote.

Data Encryption Best Practices

Everything below assumes you have decided what to protect. Start there, because the cheapest data to protect is data you never collected.

1. Do not store what you do not need

OWASP’s Cryptographic Storage Cheat Sheet leads with this, and it is the most ignored advice in the document. The best way to protect sensitive information is to not store it in the first place, and the guidance singles out credit card data because attackers want it and PCI DSS governs how it must be held.

Practical version: if a field has no owner, no retention policy and no query that reads it, delete the column.

2. Choose algorithms from an approved list, not from a tutorial

  • Symmetric: AES at 128 bits minimum, 256 bits preferred, in an authenticated mode like GCM or a properly composed encrypt-then-MAC construction.
  • Asymmetric: RSA at 2048 bits minimum, or ECC at equivalent strength.
  • Hashing for integrity: SHA-256 or stronger. SHA-1 is deprecated.
  • Hashing for passwords: Argon2id, scrypt, bcrypt, or PBKDF2, never a fast hash.
  • Transport: TLS 1.2 with modern cipher suites at minimum, TLS 1.3 preferred.

Unencrypted modes like ECB deserve a mention because they still ship. ECB encrypts identical plaintext blocks to identical ciphertext blocks, which means patterns survive encryption. It is not a subtle flaw. It looks like a bitmap of your original data.

3. Encrypt the sensitive fields, not just the volume

Full disk encryption is a compliance checkbox with real but narrow value. Field-level encryption is what protects you from an application compromise, because the attacker who reaches your app can still read whatever the app can read.

Decide per field. Names, addresses, government identifiers, health data and payment instruments deserve application-level treatment. A product catalog does not.

4. Validate certificates and never disable verification

Turning off TLS verification to make a staging environment work is how you ship a man-in-the-middle vulnerability to production. If a certificate fails to validate, that is either a misconfiguration or an interception attempt, and both deserve a fix rather than a bypass flag.

5. Encrypt your backups, and treat the key as a separate problem

Ransomware operators target backups first, because a clean backup is the thing that ends an incident cheaply. An encrypted backup with a key stored on the same domain controller is not a backup, it is a hostage. Protecting backup data from ransomware covers immutability and offline copies, both of which matter more than the cipher you choose.

6. Stop secrets from spreading

Use a secrets manager. Restrict who can read the secret, log every access, and rotate on schedule and on staff departure. A spreadsheet of production keys shared in a chat thread is the single most common way encryption quietly stops protecting anything.

For the broader operational picture, including classification and handling procedures, how to handle sensitive information covers the process side that encryption alone cannot solve.

7. Watch the exits

Encryption protects data at rest and in transit. It does nothing about a support agent pasting a customer record into a personal email. That is the gap data loss prevention exists to close, and data loss prevention best practices covers the controls that catch it, from pattern matching to egress monitoring.

8. Plan for the quantum transition now, slowly

NIST finalized three post-quantum standards on August 13, 2024:

  • FIPS 203, ML-KEM, for key encapsulation.
  • FIPS 204, ML-DSA, the primary standard for digital signatures.
  • FIPS 205, SLH-DSA, a hash-based signature scheme.

They took effect August 14, 2024. The practical implication for most teams is a migration project, not an emergency, because the threat model is “harvest now, decrypt later” against long-lived confidentiality. If you hold data that must stay secret for a decade, that clock started already.

One thing not to panic about: symmetric encryption. NIST’s own post-quantum FAQ states that Grover’s algorithm will provide little or no advantage in attacking AES, and that AES-128 will remain secure for decades to come. The quantum problem is with public-key cryptography, not with your AES-256 database columns.

Common Mistakes

  • Rolling your own crypto. Not because libraries are perfect, but because you will get the mode, the nonce and the padding wrong in ways that are invisible until they are exploited.
  • Reusing a nonce or IV. In GCM specifically, a repeated nonce can leak the authentication key. Generate nonces randomly and never reuse them per key.
  • Encrypting with no integrity check. Confidentiality without authentication allows ciphertext manipulation. Use AEAD modes.
  • Storing keys next to the ciphertext. Common in badly configured cloud storage, where the key sits in the same bucket or the same repo.
  • Using a fast hash for passwords. SHA-256 with a salt is still a fast hash, and a GPU eats it for breakfast.
  • Believing encryption equals compliance. Encryption is one control. Auditors ask about key custody, access logging and retention, and that is where the findings land.
  • Forgetting the destruction step. A retired key that still exists in three backups means the data it protected is still decryptable.

FAQ

Is AES-256 better than AES-128?

Stronger in a theoretical sense, and unnecessary for most workloads. AES-128 uses 10 rounds, AES-192 uses 12, and AES-256 uses 14 per FIPS 197. AES-256 costs a little performance and buys margin against future cryptanalysis. OWASP recommends AES at 128 bits minimum with 256 preferred, which is a fair summary: use 256 where the data is worth it, and do not rebuild a working system to change 128 to 256.

Does encryption hide data from my internet provider?

For content, yes, if the whole path is encrypted end to end. TLS protects the payload from anyone in the middle, including your ISP. What it does not hide is metadata: which IP you connected to, roughly when, and how much data moved. Traffic analysis remains possible even when the content does not.

What is the difference between encryption and hashing?

Encryption is reversible with a key. Hashing is one-way and produces a fixed-length digest. Use encryption when you need the data back. Use hashing when you only need to verify a match, which is why passwords are hashed and stored records are encrypted.

Why does TLS 1.3 not support RSA key exchange?

Because it removed static RSA and Diffie-Hellman cipher suites, leaving ephemeral mechanisms that provide forward secrecy. The tradeoff is a slightly different handshake, and the gain is that a stolen server key does not retroactively unlock previously recorded sessions.

Is it worth encrypting data that is already in a locked database?

Yes, and the reason is insider access and application compromise. Database access controls stop people without credentials. Encryption stops people who have them but should not see specific fields, and it stops an attacker who reaches the data files directly.

Do I need to worry about quantum computers breaking my encryption today?

For symmetric encryption, no. For public-key cryptography, it is a planning issue rather than a 2026 emergency. NIST has finalized FIPS 203, 204 and 205, and the work now is inventory: find where you use RSA and ECC, and map which systems hold data with a long secrecy lifetime. Start there rather than starting with a vendor pitch.

Bottom Line

Encryption is a solved problem at the algorithm level and an unsolved one at the operational level. AES is fine. TLS 1.3 is fine. Argon2id is fine. Nobody is breaking these today.

What breaks is the key sitting in a config file that got committed, the backup encrypted with a key stored on the same server, the pepper in the database alongside the hashes, the certificate check someone disabled in a hurry, and the retired key that never got destroyed.

So the sequence I would follow: decide what you actually need to store, pick algorithms from the approved list, encrypt specific fields rather than trusting volume encryption alone, put keys in a managed service with access logging and a rotation schedule, and then test the whole thing by asking one question. If an attacker got your database tonight, what would they actually be able to read?

If the answer is “everything,” the cipher was never the problem.

Author