我有一个朋友是白帽黑客。他说 md5 并没有那么糟糕,实际上真的很安全,只要我们正确使用它。
我相信他是对的。据我所知,有 3 种方法可以打破哈希:
- 使用彩虹表(可以通过长/随机盐来保护)
- 碰撞(可以通过多种盐或哈希来防止 - 如下例所示)
- 生成时间(如果我们为每个用户使用足够长的盐值 - AFAIK,这并不重要)
我和我的朋友认为 Blowfish 并不是真正需要的,它也可能是有害的,因为它可以减慢密码验证过程,并且它可以与 DDOS 攻击一起使用,即使攻击资源较少也可以破坏服务器。
所以,我想确保以下算法真的安全吗?而且,是否有真正的理由使用 Blowfish 哈希算法?
// return a 256 bit salt + 128 bit md5 binary hash value
function hash(password, salt=null)
{
salt = (salt != null) ? salt : Random256BitBinaryValueGenerator();
// What about using another user-specified parameter, like email address as salt?
return salt + md5(salt + password) + md5(password + salt);
// Or just use a non-cryptographic hash algorithm like crc32 to prevent collisions:
// return salt + md5(salt + password) + crc32(salt + password);
// Or even use two different salts:
// return salt + md5(salt + password) + md5('C' + salt + password);
}
// check password
function check(password, hash_value)
{
return hash(password, substring(hash_value, 0, 32)) == hash_value;
}