Aller au contenu
uencoder

Stocker chiffrement clés securely

Clés doit jamais être hardcoded ou committed en source control. Apprendre HSM, KMS, envelope chiffrement, et clé derivation motifs pour sûr clé storage.

  1. 1

    The golden rule: never store encryption keys in plaintext alongside the data they encrypt. Options from most to least secure: HSM (hardware), KMS (cloud service), envelope encryption (master key wraps data keys), key derivation (derive from a password/passphrase).

  2. 2
    Dérivation de clé PBKDF2 →

    Derive an encryption key from a user password using PBKDF2 with a high iteration count (100,000+). The salt must be random and stored separately. This is for user-controlled keys where no server-side storage exists.

  3. 3
    Générateur de hash bcrypt →

    Hash a master password with bcrypt for authentication. Note: bcrypt output is not suitable as an encryption key directly — use PBKDF2/scrypt for key derivation, bcrypt for password verification.

  4. 4
    Chiffreur AES →

    Use the derived key to encrypt data. The key never touches disk in plaintext — it exists only in memory during the encryption operation and is zeroed afterward.

  5. 5

    For server-side applications, use a KMS (AWS KMS, GCP KMS, Azure Key Vault) or HSM. The master key never leaves the hardware; you call an API to encrypt/decrypt. For client-side, derive keys from user passwords with a strong KDF and store only the salt.

Questions fréquentes

Can I store a key in an environment variable?
Environment variables are better than hardcoding but still visible to anyone with process access (e.g., /proc/pid/environ on Linux). Use a KMS or secrets manager (Vault, AWS Secrets Manager) for production. Environment variables are acceptable for development only.
What is the difference between PBKDF2 and bcrypt?
PBKDF2 is a KDF that produces a key of any length — use it for encryption keys. bcrypt is a password hashing function with a fixed output — use it for password verification. They serve different purposes and are not interchangeable.

Workflows résolvant cette tâche

Outils associés