良好的加密哈希函数
可能的重复:
PHP 密码的安全哈希和盐
我正在制作一个网站,并且我需要一个安全的算法来存储密码。 我首先想到的是 bcrypt,但后来我发现我的主机不支持它,而且我无法更改主机。
我的主机允许这种加密:
- 标准 DES
和这些哈希值:
- MD5
- md2、md4 和 md5 md5
- sha1、sha256、sha384 和sha512ripemd128
- 、ripemd160、ripemd256 和ripemd360
- 漩涡
- tiger128,3、tiger160,3、tiger192,3、tiger128,4、tiger160,4 和Tiger192,4
- snefru
- gost
- adler32
- crc32 & crc32b
- haval128,3, haval160,3, haval192,3, haval224,3, haval256,3, haval128,4, haval160,4, haval192,4, haval224,3, haval256,4, haval128,5, haval160,5, haval192 ,5, 哈弗224,5 & haval256,5
那么,你们中的任何人都可以用它和盐修复一个好的算法吗?
Possible Duplicate:
Secure hash and salt for PHP passwords
I am making a website, and I need a secure algorithm to store passwords.
I was first thinking of bcrypt, but then I found out my host did not support it and I am not able to change host.
My host allow this encryption:
- Standard DES
And these hashes:
- MD5
- md2, md4 & md5
- sha1, sha256, sha384 & sha512
- ripemd128, ripemd160, ripemd256 and ripemd360
- whirlpool
- tiger128,3, tiger160,3, tiger192,3, tiger128,4, tiger160,4 & tiger192,4
- snefru
- gost
- adler32
- crc32 & crc32b
- haval128,3, haval160,3, haval192,3, haval224,3, haval256,3, haval128,4, haval160,4, haval192,4, haval224,3, haval256,4, haval128,5, haval160,5, haval192,5, haval224,5 & haval256,5
So, can anyone of you fix a good algorithm with that and a salt, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您根本不应该存储加密(甚至未加密)的密码。相反,使用加盐哈希(拉伸,例如使用 PBKDF2),最好是 SHA2-512。
作为参考,这里是列出的哈希值的分类(有关详细信息,请参阅 wikipedia):
加密(不是哈希函数):DES
非加密校验和(可笑):adler32、crc32、crc32b
损坏:MD2、MD4、MD5、SHA1
可能损坏:Tiger、snefru、GOST、HAVAL*
可能安全:SHA2-256/384/512、RIPEMD-128/256、RIPEMD-160/320、WHIRLPOOL
请注意,强度是指找到与已知匹配的任何密码的攻击哈希(原像攻击)。此外,上述排序是偏执的,立即丢弃任何具有任何已知漏洞的哈希。
You shouldn't store encrypted (or even unencryped) passwords at all. Instead, use salted hashes (stretched, e.g. with PBKDF2), preferably SHA2-512.
For reference, here is a classification of the listed hashes (See wikipedia for details):
Encryption (not a hash function): DES
Non-cryptographic checksums (laughable): adler32, crc32, crc32b
Broken: MD2, MD4, MD5,SHA1
Probably broken: Tiger, snefru, GOST, HAVAL*
Probably safe: SHA2-256/384/512, RIPEMD-128/256, RIPEMD-160/320, WHIRLPOOL
Note that the strength refers to the attack of finding any password that matches a known hash (preimage attack). Also, the above sorting is paranoid, instantly discarding any hash with any known vulnerabilities.
crc32、adler32 等并不是为了加密安全而设计的——它们只是快速校验和算法。我认为 salted SHA-256 应该提供安全性和兼容性的良好组合。
说得不那么严重的是,我曾经记得在一台慢速服务器上使用 salted MD5,该服务器预计会承受中等负载。因此,我决定用 32 位随机盐填充它,并将整个内容存储为十六进制 - 它给人的印象是整个内容是未加盐的 SHA-1。我真诚地希望有人浪费宝贵的时间在被盗的转储上运行彩虹表!
安全性并不全在于更昂贵的散列:)
crc32, adler32 etc. are not designed to be cryptographically secure -- they're merely fast checksum algorithms. I think salted SHA-256 should offer a good combination of security and compatibility.
On a somewhat less serious note, I once recall using salted MD5 on a slow server that was expected to tank moderate load. So I decided to pad it with a 32-bit random salt, and stored the whole thing as hexadecimal -- it gave off the impression the whole thing was unsalted SHA-1. I sincerely hope someone wasted precious time running rainbow tables on the stolen dump!
Security isn't really all about more expensive hashing :)
您应该
You should
您应该将密码存储为如上所述的哈希值,而不是加密的。
哈希函数基本上是一种单向转换,它总是为相同的输入参数生成相同的哈希值。不应将哈希值转换回其原始形式,否则哈希函数将被视为损坏。
加密是一种双向转换,如果您有密钥,您可以将加密数据转换回其原始形式。
通过将密码存储为散列,并且由于它们是一种转换方式,因此即使有人掌握了数据库也无法提取它们。
检查密码时,只需使用与存储的密码相同的哈希函数对其进行转换,然后对照数据库进行检查。
You should store passwords as hashes as mentioned above, not encrypted.
A hash function is basically a one way transformation which always produces the same hash for the same input argument. It should not be possible to transform the hash back to its original form, or the hash function is to be considered broken.
An encryption is a two way transformation where you can transform the encrypted data back into its original form if you have the key.
By storing passwords as hashes, and as they are one way transformed, they can not be extracted even if someone were to get hold of the database.
When checking a password simply transform it with the same hash function you used on your stored password and check against the database.
正如 gnur 所说,您需要决定是否要对密码进行散列或加密。如果这些是您自己的用户的密码并且这些密码仅在您的系统上使用,则使用盐和拉伸对它们进行哈希处理。在可用的哈希算法中,请使用 SHA-256 或 SHA-512。对于 salt,使用 128 个随机位(16 字节)。理想情况下使用加密 RNG,但在紧要关头也可以使用非加密 RNG。无论如何,攻击者都被认为知道盐。足够长,处理单个密码大约需要 0.1 秒。这限制了攻击者每秒只能尝试十次破解密码。
如果您要存储登录外部系统的密码,那么您将需要加密密码并在需要时解密。 DES 是您唯一真正的选择,除非您还有 3DES(又名 Triple DES 或 DESede)可用。我很惊讶 AES/Rijndael 不可用。如果是,那么我们优先于 DES。
As gnur said, you need to decide if you want to hash or encrypt passwords. If these are passwords for your own users and the passwords are only being used on your system, then hash them using salt and stretching. Of the hash algorithms you have available use SHA-256 or SHA-512. For salt use 128 random bits (16 bytes). Ideally use a cryptographic RNG though a non-crypto RNG will do in a pinch. The attacker is assumed to know the salts anyway. Stretch enough that it takes about 0.1 second to process a single password. This limits any attacker to ten attempts at breaking a password every second.
If you are storing passwords to log on to an external system then you will need to encrypt the passwords and decrypt them when needed. DES is your only real option here, unless you also have 3DES (aka Triple DES or DESede) available. I am surprised that AES/Rijndael is not available. If it is then us it in preference to DES.