我不时听到"使用bcrypt在PHP中存储密码,bcrypt规则"的建议.
但是什么bcrypt呢?PHP没有提供任何此类功能,维基百科关于文件加密实用程序的唠叨和Web搜索只是揭示了不同语言的Blowfish的一些实现.现在Blowfish也可以通过PHP获得mcrypt,但是如何帮助存储密码?Blowfish是一种通用密码,它有两种工作方式.如果它可以加密,则可以解密.密码需要单向散列函数.
解释是什么?
Coda Hale的文章"如何安全地存储密码"声称:
bcrypt内置了盐来防止彩虹表攻击.
他引用了这篇论文,其中说在OpenBSD的实现中bcrypt:
OpenBSD从arcfour(arc4random(3))密钥流生成128位bcrypt salt,并使用内核从设备时序收集的随机数据进行种子处理.
我不明白这是如何工作的.在我的盐概念中:
当我使用带有bcrypt的Devise(一个Rails登录管理器)时,数据库中没有salt列,所以我很困惑.如果盐是随机的并且没有存储在任何地方,我们如何可靠地重复散列过程?
简而言之,bcrypt如何内置盐?
我想在数据库中存储散列密码(使用BCrypt).什么是好的类型,哪个是正确的长度?密码是否与BCrypt长度相同?
编辑
示例哈希:
$2a$10$KssILxWNR6k62B7yiX0GAe2Q7wwHlrzhF3LqtVvpyvHZf0MwvNfVu
在对一些密码进行哈希处理之后,似乎BCrypt总是生成60个字符的哈希值.
编辑2
很抱歉没有提及实施.我正在使用jBCrypt.
bCrypt的javadoc有如何加密密码的代码:
String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
Run Code Online (Sandbox Code Playgroud)
要检查明文密码是否与先前已经散列的密码匹配,请使用checkpw方法:
if (BCrypt.checkpw(candidate_password, stored_hash))
System.out.println("It matches");
else
System.out.println("It does not match");
Run Code Online (Sandbox Code Playgroud)
这些代码片段向我暗示随机生成的盐被丢弃.是这种情况,还是只是一个误导性的代码片段?
Ruby 1.9.3
Gemfile的一部分
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
Run Code Online (Sandbox Code Playgroud)
当我尝试安装宝石时,我收到一个错误
alex@ubuntu:~/$ bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Enter your password to install the bundled RubyGems to your system:
#####............................................................
Installing bcrypt-ruby (3.0.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection.
Results …Run Code Online (Sandbox Code Playgroud) 我已经读过,在对密码进行散列时,许多程序员建议使用BCrypt算法.
我正在使用C#进行编程,并且想知道是否有人知道BCrypt的良好实现?我找到了这个页面,但我真的不知道它是不是假的.
选择密码哈希方案时应该注意什么?BCrypt是一个"好"的实现吗?
有谁知道bcrypt的一个很好的实现,我知道这个问题之前已被问过,但它得到的答案很少.我有点不确定只是选择在谷歌中出现的实现,并且我认为我最好在System.Security.Cryptography命名空间中使用sha256,至少我知道它是支持的!你有什么想法?
来自github:
哈希密码:
var bcrypt = require('bcrypt');
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash("B4c0/\/", salt, function(err, hash) {
// Store hash in your password DB.
});
});
Run Code Online (Sandbox Code Playgroud)
要检查密码:
// Load hash from your password DB.
bcrypt.compare("B4c0/\/", hash, function(err, res) {
// res == true
});
bcrypt.compare("not_bacon", hash, function(err, res) {
// res = false
});
Run Code Online (Sandbox Code Playgroud)
从上面来看,如何在比较中不涉及盐值?我在这里错过了什么?
什么是密码散列的理想bcrypt工作因素.
如果我使用因子10,在我的笔记本电脑上散列密码需要大约1秒.如果我们最终得到一个非常繁忙的网站,那么只需检查一下人们的密码即可完成大量工作.
也许最好使用7的工作因子,将每个笔记本电脑登录的总密码哈希工作减少到大约0.01秒?
您如何决定暴力安全与运营成本之间的权衡?
我正在为学校开展一个nodejs项目.我无法用npm安装bcrypt所以我安装了bcrypt-nodejs并且该项目昨天工作正常.但今天,当我做"节点应用程序"时,我有这个错误:
/.../node_modules/bcrypt/node_modules/bindings/bindings.js:79
throw e
^
Error: /.../node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/.../node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/.../node_modules/bcrypt/bcrypt.js:1:97)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Run Code Online (Sandbox Code Playgroud)
我的package.json文件如下所示:
{
"name": "Supinfarm",
"version": "0.0.0",
"env": {
"PYTHON": "/usr/bin/python2.6"
},
"dependencies": {
"express": "3.1.0",
"connect-flash": "*",
"jade": "*",
"stylus": "*",
"passport": "*",
"passport-local": "*",
"mongoose": "*",
"bcrypt": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
我在Linux上ubuntu 10.04 LTS我试图在google上找到解决方案但没有成功......有人可以帮助我吗?