Question #47 of 60•Security & Auth•Medium• ~3 min read

How do you design secure storage for Passwords, API Keys, and Sensitive PII?

Executive Takeaway

Analyze bcrypt key stretching, envelope encryption with KMS, and database column-level encryption.

Architectural Breakdown & AnalysisFAANG Aligned

Protecting user credentials and sensitive PII data requires multiple layers of cryptographic defense.

1. Password Hashing (Argon2id / bcrypt)

Never store plaintext passwords or plain MD5/SHA256 hashes. Use salted, adaptive memory-hard algorithms like Argon2id or bcrypt with a work factor $\ge 12$ to prevent GPU brute-force attacks.

2. Envelope Encryption for PII Data

  • Data Encryption Key (DEK): Encrypts sensitive database column data locally.
  • Key Encryption Key (KEK): Stored securely in HSM / AWS KMS to encrypt the DEK.
python
# Hashing passwords securely
import bcrypt

hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(rounds=12))
WARNING — Secret Management Anti-Pattern

Never hardcode secrets in Git repositories. Use secret managers like HashiCorp Vault or AWS Secrets Manager.

Key Architectural Comparison

Data CategoryCryptographic StandardKey ManagementSalt / Nonce Requirement
User PasswordsAdaptive Slow Hashing (Argon2id / bcrypt)Irreversible one-way hashUnique random salt per password (prevents Rainbow Tables).
PII & Card NumbersAuthenticated Encryption (AES-256 GCM)AWS KMS / HashiCorp VaultUnique 96-bit Initialization Vector (IV) per record.
API Keys & TokensHigh-Speed Digest (HMAC-SHA256)Secret signature keySalted token prefix.
Previous QuestionWhat are the trade-offs of Blue-Green, Canary, and Rolling Deployments?Next Question How do you design a Nearby Places Geospatial Service (Uber / Yelp)?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.