About this article
As the fourth installment of the âSecurity Architectureâ category in the series âArchitecture Crash Course for the Generative-AI Era,â this article explains encryption.
Modern systems are basically defended in 3 layers: at-rest, in-transit, and in-use. This article explains symmetric/public-key encryption, TLS, hashing, KMS, Envelope Encryption, and TDE - presenting the practical iron rule that encryption strength equals key-management strength.
Before you read this
This article uses a good deal of security vocabulary â authentication, authorization, encryption. If that is unfamiliar, reading the primer "Security and Authentication" first makes it far easier to follow. You can also look anything up in the glossary as you read.
What is encryption in the first place
Encryption is, roughly speaking, âthe technology of converting data into an unreadable form so that only someone with the correct key can restore it.â
Imagine a wax seal on a letter. With a wax seal (encryption), even if someone peeks at it along the way, they canât read the contents. However, if the signet ring (key) used to make the seal is stolen, anyone can open and forge it. Digital encryption works the same way: as long as the key is securely managed, the data is protected even though the algorithm itself is public. In other words, encryption strength equals key-management strength.
Why encryption matters
Steal the database, backups and all, and encrypted data still cannot be read. Most of the leaks that make the news trace back to storing things in plaintext. GDPR, data-protection law and PCI DSS all require personal and card data to be encrypted, and a violation brings fines in the hundreds of millions. Modern browsers warn on HTTP, so sending traffic in the clear is effectively prohibited.
What matters most is that encryption is not âsafe because we installed itâ: key management is the whole of it. Incidents where somebody believed they had encrypted the data while leaving the key sitting in plaintext keep on happening.
The three places encryption happens
Encryption is classified into 3 by âwhere to defend.â In modern architecture, encrypting all 3 layers is standard.
| Type | Target | Representative tech |
|---|---|---|
| At Rest | DB, files, backups | TDE (Transparent Data Encryption), AES-256 |
| In Transit | Network communication | TLS 1.3, mTLS |
| In Use | In memory, during computation | TEE (Trusted Execution Environment, isolated execution area in CPU), homomorphic encryption |
In-use encryption is still developing and hard to implement, but at-rest and in-transit are already established as standard tech and are required in modern systems.
The basic toolkit
Symmetric and public keys â TLS is a hybrid of both
Two fundamental encryption principles where use cases differ. Either alone is insufficient; modern systems combine both.
| Symmetric key | Public key | |
|---|---|---|
| Keys | One (shared) | Two (public/private) |
| Speed | Fast | Slow (1000x) |
| Key distribution | Hard | Easy |
| Representatives | AES-256 | RSA, ECDSA |
| Use case | Bulk data encryption | Key exchange, signing |
Modern TLS uses both - public-key encryption to safely exchange a symmetric key, and the body data encrypted with the fast symmetric key. This hybrid approach is standard.
On the wire, the de facto standard is TLS; HTTPS is simply HTTP carried over it. The modern web has TLS 1.3 as the latest, with TLS 1.0/1.1 already deprecated, 1.2 as minimum, 1.3 as recommended.
| Version | Status |
|---|---|
| SSL 3.0 and below | Banned (vulnerable) |
| TLS 1.0 / 1.1 | Deprecated (major browsers ended support) |
| TLS 1.2 | Minimum, backward-compatible |
| TLS 1.3 | Recommended, fast, safe |
TLS certificates can be obtained free via Letâs Encrypt, and managed services like CloudFront and ALB auto-renew. Paid EV certificates have lost UX-improvement effect and are now mostly unnecessary.
Hashing â for passwords, use something deliberately slow
A function that converts source data one-way, irreversibly - hashing. Used for password storage, tampering detection, and digital signatures. Often confused with encryption, but the fundamental difference is being non-decryptable.
| Use case | Algorithm |
|---|---|
| Password storage | bcrypt, Argon2, scrypt |
| Tampering detection | SHA-256, SHA-3 |
| Digital signature internal | SHA-256, SHA-384 |
| Legacy (deprecated) | MD5, SHA-1 |
Using general hashes (SHA-256) for passwords is strictly forbidden. Too fast for brute force. Use âintentionally slowâ hashes like Argon2 or bcrypt, and always add âsaltâ (a string different per user).
KMS and envelope encryption â the app never holds the key
The mechanism for safely managing keys - the heart of encryption - is KMS. Holding keys plaintext on the app side is strictly forbidden; manage with dedicated hardware (HSM = Hardware Security Module, dedicated device physically protecting encryption keys) or KMS. In cloud, itâs provided as a standard service.
| Service | Characteristics |
|---|---|
| AWS KMS | AWS-integrated, cheap |
| Google Cloud KMS | GCP-integrated |
| Azure Key Vault | Azure-integrated, also Secret management |
| HashiCorp Vault | OSS, multi-cloud |
| Hardware HSM | FIPS 140-2 Level 3 compliant |
Keys go through periodic rotation (auto-update) as the basis - KMS realizes this transparently.
For large volumes of data, envelope encryption is the standard pattern.
Envelope Encryption is the standard pattern for efficiently encrypting bulk data. The data is encrypted with a fast symmetric key, and that key itself is encrypted with the KMS key - a nested structure balancing safety and performance.
Data --- [DEK: Data Encryption Key] ---> Encrypted data
â
âââ [KEK: KMS Key] âââ> Encrypted DEK
Encrypting data using KMS directly is slow due to network round-trips, but with the Envelope approach, KMS is called only at the start and subsequent encryption is local. AWS S3 and BigQuery internals also use this approach.
For key management, leave it to KMS. Not holding keys app-side is the rule.
TDE and client-side encryption
TDE is a feature where the DB itself automatically encrypts data, realizing at-rest encryption without app-side code changes. A standard feature of cloud DBs and enterprise DBs - just enabling it completes at-rest encryption.
| DB | TDE support |
|---|---|
| PostgreSQL (managed) | Auto on RDS, Cloud SQL |
| SQL Server | TDE standard feature |
| MySQL | Supported from 8.0 |
| Oracle | TDE standard feature |
| BigQuery, Snowflake | Always-on encryption by default |
Many people misunderstand âencryption = TDE,â but TDE is only at-rest encryption - app-DB communication and in-app memory need separate measures.
Where stronger protection is required, as in a password manager or a confidential-notes service, you can encrypt on the client before sending.
A method that encrypts on the app side before sending to the server, creating a state where even the server canât see plaintext. The âzero-knowledge designsâ of LastPass, 1Password, Signal, and Proton Mail are this.
| Pros | Cons |
|---|---|
| Safe even on server leak | Search/aggregate impossible server-side |
| True end-to-end | Key loss makes recovery impossible |
| Easy regulatory response | High implementation difficulty |
For things like credit card numbers, passwords, and confidential memos, unless server-side decryption is needed, client-side encryption is worth considering.
A related tool is the digital signature, used for tamper detection.
What guarantees data authenticity (itâs genuine) and integrity (not tampered) is the digital signature. An application of public-key encryption - the sender signs with the private key, the receiver verifies with the public key.
| Use case | Example |
|---|---|
| Contracts | DocuSign, Cloud Sign |
| Code distribution | Code signing, software distribution |
| Container images | Cosign, Notary |
| SBOM | Software composition attestation |
In particular, signing container images (Cosign) has rapidly spread recently as a supply-chain-attack countermeasure.
How to choose â sensitivity, and the numeric gates on algorithms
The strength of encryption is decided by how sensitive the data is. Public information gets TLS only; ordinary business data gets TLS plus TDE; personal data adds column-level encryption; card data is handled through PCI DSS-compliant tokenisation â payment-processor tokens from Stripe and the like, with no card number in your own database. Top-secret data in finance and healthcare goes up to an HSM plus client-side encryption. If you are fully on cloud, managed KMS plus TDE lets you turn encryption on by default and covers around 80% of the regulatory requirement.
Standard values as of April 2026.
| Use case | Recommended algorithm | NG / legacy |
|---|---|---|
| Symmetric-key encryption | AES-256-GCM (authenticated encryption) | AES-128-ECB, DES, 3DES |
| Public-key encryption | RSA 4096-bit / ECDSA P-256+ | RSA 1024, DSA |
| Hash (password) | Argon2id (memory 64MB, time 2) / bcrypt cost 12+ / scrypt | MD5, SHA-1, SHA-256 alone |
| Hash (tampering detection) | SHA-256 / SHA-384 / SHA-3 | MD5, SHA-1 |
| TLS version | TLS 1.3 (or 1.2) | SSL / TLS 1.0 / 1.1 (all deprecated) |
| Random generation | CSPRNG (crypto.randomBytes etc.) | Math.random() |
| Key rotation frequency | 90 days / immediate on leak | Permanent use |
| TLS cert expiry | 90 days (Letâs Encrypt auto-renew) | 1+ year manual |
| Post-quantum (future consideration) | ML-KEM / ML-DSA (NIST 2024 release) | - |
âArgon2id (winner of the 2015 Password Hashing Competition)â is the standard for password hashing as of 2026. bcrypt remains usable, but Argon2id is the top candidate for new builds. âPBKDF2 used with old iteration countsâ gets broken, so a minimum of 600,000 iterations (OWASP 2023 recommendation) is required.
The rule is donât deviate one step from standard algorithms. Custom encryption is absolutely taboo.
Three scenarios
If you are building solo or at a startup
TLS 1.3, a managed KMS and TDE switched on. Terminate TLS at CloudFront or an ALB, leave TDE on for RDS or BigQuery as it comes, and hash passwords with Argon2id. That alone covers most of what you need, regulatory response included, and it costs almost nothing.
If you are a small or mid-size SaaS
The same baseline plus column-level encryption for personal data, and tokenisation the moment card data appears. Do not put card numbers in your own database; hand them to Stripe or Adyen and keep only the token. Design it so that a database leak does not leak card data, and PCI DSS scope shrinks dramatically.
If you are a large or regulated enterprise
A FIPS 140-2 Level 3 HSM, column-level encryption and audit logs on every key access, with key administrators separated under segregation of duties. Where confidentiality demands it, client-side encryption keeps even your own servers from seeing plaintext. The price is that search and aggregation become impossible and a lost key means unrecoverable data, so the recovery procedure is the hardest part of the design.
AI decision axes â Let the AI write the wrapper code and nothing else
Why you shouldnât have AI write encryption code
AI can write the âusageâ of encryption, but its judgment on whether the âusage is correctâ canât be trusted. For example, when generating AES encryption code, it may produce code using ECB mode (a dangerous mode where identical plaintext blocks produce identical ciphertext) or code with fixed initialization vectors (IVs).
For encryption, the principle is âonly have AI write KMS/SDK calling code.â Wrapper code like AWS KMS encrypt/decrypt calls, TLS certificate configuration, and bcrypt hash calls can be safely delegated to AI. Having AI write encryption algorithm implementations or key-generation logic should be avoided.
Declare KMS auto-rotation settings in IaC
AWS KMS key-rotation settings are just one line addition in Terraform, but without that line, keys stay fixed permanently. When having AI write Terraform code, it may create the KMS resource but omit rotation settings. A CI tfsec rule that detects âKMS key without rotation settingâ is effective.
Pitfalls and forbidden moves
Here are the six most dangerous instances of the pattern âleaking while believing it was encryptedâ.
| Forbidden move | Why it is bad â what to do instead |
|---|---|
| Hardcoding a key into source or .env | it stays in Git history for ever and bots pick it up within seconds â put it in KMS or Secrets Manager |
| Implementing your own encryption algorithm | an area even specialists stay out of â stay with the standard AES and TLS libraries |
| Hashing passwords with MD5, SHA-1 or no salt | GPU cracking gets through instantly â Argon2id with a salt |
| Using AES in ECB mode | the same mine that produced the 2013 Adobe breach, where 150 million records were decoded â use AES-GCM |
| Never rotating keys | no insurance against the assumption that a key eventually leaks â 90-day automatic rotation |
| Adopting AI-generated cryptographic code as it stands | old algorithms and fixed IVs creep in â require expert review |
Authorâs note - cases where âencryptedâ wasnât actually protected
The story of âweâre encrypted so weâre fineâ collapsing accounts for many recent large-scale leaks - a perennial industry talking point.
In the October 2013 Adobe info-leak incident, about 150M passwords were leaked âencrypted,â but multiple implementation flaws - same key, ECB mode, and common password-hint field - aligned, and ciphertext-pattern analysis practically deciphered them. A case told as the event that drove home to the world that âencryptedâ and âprotectedâ are different things.
Another, the 2022 LastPass info-leak incident, also left a heavy lesson. The encrypted password vault itself was taken, and it was later revealed that some usersâ iteration counts (PBKDF2 repeats) remained at old settings, with low resistance to brute force. It became the trigger for the lesson âdesign must include not just âis it encryptedâ but âhow slow a hash you usedââ being widely shared.
I once left a test-purpose AES key in .env.example and pushed to Git, then got panicked half a year later when secret-scanning detected it. Since it wasnât a production key, the damage was zero, but it was an event where I keenly felt that whether you can explain a keyâs lifespan, path, and location matters. Both are lethal blows from âimplementation laxness,â not flashy attacks - they slap home the lesson that encryption is âinsufficient just to install.â
Mundane key-management mistakes always happen. Ask not âdid you install itâ but the keyâs lifespan and path.
What to decide - what is your projectâs answer?
For each of the following, try to articulate your projectâs answer in 1-2 sentences. Starting work with these vague always invites later questions like âwhy did we decide this again?â
- Communication encryption (TLS 1.2/1.3, mTLS necessity)
- Storage encryption (TDE, KMS, column-level)
- Key management (KMS, Vault, HSM)
- Password hashing (Argon2 / bcrypt + salt)
- Key rotation (frequency, automation)
- Client-side encryption (necessity)
- Signing (code, container, contracts)
Write your answers down as an ADR. A concrete guide to writing them is here.
Related Articles
Summary
This article covered encryption, including symmetric/public keys, TLS, hashing, KMS, Envelope Encryption, TDE, and the practical iron rule.
Encrypt in 3 layers, entrust keys to KMS, hash passwords with Argon2/bcrypt + salt, and have specialists review encryption code. That is the practical answer for encryption design in 2026.
Next time weâll cover network security (FW, WAF, IDS/IPS, DDoS countermeasures).
I hope youâll read the next article as well.
Also popular with readers
đ Series: Architecture Crash Course for the Generative-AI Era (55/95)