ruby – BCrypt说长,类似的密码是等价的 – 我,宝石或密码学领域的问题?

我一直在试验BCrypt,并发现了以下内容.如果重要的话,我正在运行ruby 1.9.2dev(2010-04-30 trunk 27557)[i686-linux]
require 'bcrypt' # bcrypt-ruby gem,version 2.1.2

@long_string_1 = 'f287ed6548e91475d06688b481ae8612fa060b2d402fdde8f79b7d0181d6a27d8Feede46b833ecd9633b10824259ebac13b077efb7c24563fce0000670834215'
@long_string_2 = 'f6ebeea9b99bcae4340670360674482773a12fd5ef5e94c7db0a42800813d2587063b70660294736fded10217d80ce7d3b27c568a1237e2ca1fecbf40be5eab8'

def salted(string)
  @long_string_1 + string + @long_string_2
end

encrypted_password = BCrypt::Password.create(salted('password'),:cost => 10)
puts encrypted_password #=> $2a$10$kNMF/ku6VEAfLFEZKJ.ZC.zcMYUzvOQ6Dzi6ZX1UIVPUh5zr53yEu

password = BCrypt::Password.new(encrypted_password)

puts password.is_password?(salted('password')) #=> true
puts password.is_password?(salted('passward')) #=> true
puts password.is_password?(salted('75747373')) #=> true
puts password.is_password?(salted('passwor')) #=> false

起初我认为一旦密码达到一定的长度,所有散列中的差异就会丢失,只有当它们非常不相似(即不同的长度)时才会被识别为不同.根据我所知的散列函数,这对我来说似乎不太合理,但我没有看到更好的解释.

然后,我尝试缩短每个long_strings以查看BCrypt能够将它们分开的地方,我发现如果我将每个长字符串缩短到100个字符左右,最后的尝试(‘passwor’)就会启动也是如此.所以现在我不知道该怎么想.

对此有何解释?

解决方法

好消息是,加密的数学基础尚未解散.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...