简体   繁体   English

bcrypt 哈希究竟如何防止彩虹表查找?

[英]How exactly does a bcrypt hash prevent rainbow table lookup?

I'm very close to understanding exactly how the compare function of bcrypt works, but there are a few missing holes in my knowledge.我已经非常接近准确地理解 bcrypt 的比较功能是如何工作的,但是我的知识中还存在一些缺失的漏洞。

My understanding so far:到目前为止我的理解:

brcypt gens a hashed password using a plain text password and a randomly generated salt. brcypt 使用纯文本密码和随机生成的盐生成散列密码。 The hashed password is a combination of the bcrypt version, the hashed salt and the concatenated hashed plain text password.散列密码是 bcrypt 版本、散列盐和串联散列纯文本密码的组合。 When a user logs in, their plain text password is ran through the compare function.当用户登录时,他们的纯文本密码通过比较函数运行。 At that point, bcrypt knows how many characters in the hash and from what offset to begin to slice the hashed salt out of the full hash.那时,bcrypt 知道散列中有多少个字符,以及从什么偏移量开始从完整散列中切出散列盐。 It then concatenates the salt with the passed in plain text password, running it through the hashing algorithm to arrive at the final hashed string.然后它将盐与传入的纯文本密码连接起来,通过散列算法运行它以获得最终的散列字符串。 The hashed string is compared to the hashed string in the database and if there is an exact character match, the password is correct.散列字符串与数据库中的散列字符串进行比较,如果字符完全匹配,则密码正确。

2 questions.. 2个问题..

  1. Aren't hashes supposed to be impossible to reverse?散列不是应该无法逆转吗? If so, then how does bcrypt know how to decrypt the hashed salt and then use it to hash the incoming plain text password.如果是这样,那么 bcrypt 如何知道如何解密散列的盐,然后使用它来散列传入的纯文本密码。 That doesn't make any logical sense to me.这对我来说没有任何逻辑意义。

  2. If brcypts algorithm is written such that it can always create a hashed salt that it always knows how to decrypt, can't hackers just use that algorithm to grab every hashed password from a database and slice the salts out?如果 brcypts 算法被编写成它总是可以创建一个它总是知道如何解密的散列盐,那么黑客不能使用该算法从数据库中获取每个散列密码并将盐分出来吗? Then it could create a rainbow table for every salt and crack each individual password?那么它可以为每种盐创建一个彩虹表并破解每个单独的密码吗? That seems logical to me.这对我来说似乎是合乎逻辑的。

Pardon if my question doesn't make any sense.如果我的问题没有任何意义,请原谅。 Happy to edit.很高兴编辑。

Read articles, read stack overflow questions, watched videos and asked a senior engineer.阅读文章,阅读堆栈溢出问题,观看视频并询问高级工程师。

A rainbow table is a pre-compiled list of every password you can find, and their hash.彩虹表是您可以找到的每个密码及其哈希值的预编译列表。

Your rainbow table has:你的彩虹桌有:

  • hash("password1234") hash("password1234")
  • hash("hunter2")哈希(“猎人2”)
  • hash("correct horse battery staple") hash("正确的马电池订书钉")

But it doesn't have:但它没有:

  • hash("ȃ@🙍♽😔ƅ😠☸☑+password1234") hash("ȃ@🙍♽😔ƅ😠☸☑+password1234")
  • hash("ȃ@🙍♽😔ƅ😠☸☑+hunter2") hash("ȃ@🙍♽😔ƅ😠☸☑+hunter2")
  • hash("ȃ@🙍♽😔ƅ😠☸☑+correct horse battery staple") hash("ȃ@🙍♽😔ƅ😠☸☑+正确的马电池主食")

You could go ahead and create a rainbow table that contains every password for this salt.您可以继续创建一个包含此盐的每个密码的彩虹表。 But that's just called a Brute Force attack.但这只是所谓的蛮力攻击。

And this second rainbow table doesn't help you with the next website that chooses a different salt:第二个彩虹表对下一个选择不同盐的网站没有帮助:

  • hash("®óó»♠☘☛🙈Ũh+password1234") hash("®óó»♠☘☛🙈Ũh+password1234")
  • hash("®óó»♠☘☛🙈Ũh+hunter2") hash("®óó»♠☘☛🙈Ũh+hunter2")
  • hash("®óó»♠☘☛🙈Ũh+correct horse battery staple") hash("®óó»♠☘☛🙈Ũh+正确的马电池主食")

And to eliminate all the guesswork, and all the difficulty of storing a salt, and deciding a salt: modern password hashing algorithms generate a different random salt for every password for you, and store the salt in the resulting hash string for you:为了消除所有猜测,以及存储盐和决定盐的所有困难:现代密码哈希算法为您的每个密码生成不同的随机盐,并将盐存储在结果哈希字符串中:

  • hash("ȼŚ😑¥dĥ😥®µ+password1234") hash("ȼŚ😑¥dĥ😥®µ+password1234")
  • hash("ČɆǝ%ËȌÁpmLȫ+hunter2") hash("ČɆǝ%ËȌÁpmLȫ+hunter2")
  • hash("♼♄ș♰;⚁f)²ŋì😱³UÍ+correct horse battery staple") hash("♼♄ș♰;⚁f)²ŋì😱³UÍ+正确的马电池主食")

Which is in essence what bcrypt does;这本质上就是 bcrypt 所做的; it generates a different salt for every password.它为每个密码生成不同的盐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM