相关疑难解决方法(0)

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
Run Code Online (Sandbox Code Playgroud)

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

然后,我尝试缩短每个long_strings以查看BCrypt开始能够区分它们的位置,并且我发现如果我将每个长字符串缩短到100个字符左右,最后的尝试('passwor')将开始也是如此.所以现在我不知道该怎么想.

对此有何解释?

ruby encryption passwords integer-overflow bcrypt

4
推荐指数
2
解决办法
1857
查看次数

标签 统计

bcrypt ×1

encryption ×1

integer-overflow ×1

passwords ×1

ruby ×1