跳到主要内容
uencoder

Understanding Salt 和 Pepper

Learn roles 的 salt 和 pepper 在 password 哈希和 如何它们补集每个其他.

问题

你 want 到理解当 到 use salt versus pepper 和如何每个 protects 针对不同攻击 vectors.

前置条件

  • Understanding 的 password 哈希
  • Knowledge 的 rainbow tables 和 brute force

步骤

  1. 1. Understand the salt

    A salt is a random value generated per password and stored alongside the hash. It ensures that identical passwords produce different hashes, defeating rainbow tables and multi-target attacks. The salt is not secret; its value comes from being unique.

    输入
    user A: salt=a1 | user B: salt=b2
    输出
    same password → different hashes
  2. 2. Understand the pepper

    A pepper is a secret value shared across all passwords but not stored with the hash. It is stored in a separate secure location (e.g., environment variable or HSM). If the database is leaked but the pepper is not, the attacker cannot crack any password without also obtaining the pepper.

    输入
    pepper: secret env var
    输出
    hash = KDF(password + salt + pepper)
  3. 3. Combine both for defense in depth

    Use a per-password salt (stored) plus a global pepper (secret). The salt defends against rainbow tables and identical-password detection. The pepper adds a second layer: even with the full database, passwords cannot be cracked without the pepper. Keep the pepper in a separate secrets manager.

    输入
    salt + pepper
    输出
    layered protection

预期结果

Password hashes 受保护通过两者 per-password salts 和 secret pepper, providing 防御在 深度.

常见错误

Storing the pepper in the database
The pepper must be stored separately from the hashes, otherwise it provides no additional protection if the database is leaked.
Using the same salt for all passwords
Generate a unique random salt per password. A shared salt defeats the purpose of salting.

排障指引

  • If you lose the pepper, all passwords become unverifiable. Back up the pepper securely.
  • If migrating, you can re-hash with a new pepper by verifying with the old one and re-hashing.

安全限制

  • The pepper is only effective if it remains secret. Store it in an HSM or secrets manager, not in source code.
  • All hashing is local.

相关工具

相关词条

参考链接