Saltar al contenido
uencoder

Almacenar cifrado claves securely

Claves debe nunca ser hardcoded o committed a source control. Aprender HSM, KMS, envelope cifrado, y clave derivation patrones para seguro clave 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
    Derivación de claves 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
    Generador 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
    Cifrador 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.

Preguntas frecuentes

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.

Flujos que resuelven esta tarea

Herramientas relacionadas