盐需要有多强?

发布于 2024-08-16 20:20:49 字数 239 浏览 2 评论 0原文

盐需要有多强?

目前,我使用此函数在用户注册时生成“唯一”盐:

$salt = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyz'), 0, 12);

然后使用 sha1 以及密码对其进行哈希处理。

你怎么认为?

附言。我不打算让 MySpace 变得更大。

How strong do salts need to be?

At the moment I use this function to generate a "unique" salt upon user registration:

$salt = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyz'), 0, 12);

I then hash it with sha1 along with the password.

What do you think?

PS. I'm not planning on getting MySpace big.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月下客 2024-08-23 20:20:49

当谈到安全性时,真正的问题并不是你的盐有多强,而是哈希函数的计算成本有多高。 SHA1 和 MD5 很便宜。如果您打算坚持使用快速(弱)哈希函数 - 这对于小型网站来说可能是完全可以接受的,我并不是有意暗示 - 那么我就不会担心盐的加密随机性。只要它是随机的,它就能达到消除精确一种攻击向量(彩虹表)的目的。

When it comes to security it's not really an issue of how strong your salt is, it's an issue of how computationally expensive the hashing function is. SHA1 and MD5 are cheap. If you're going to stick with fast (weak) hashing functions - and this may be perfectly acceptable for small sites, I don't mean to imply otherwise - then I wouldn't worry about just how cryptographically-random the salt is. As long as it's random, it'll serve its purpose of eliminating precisely one attack vector (rainbow tables).

笑脸一如从前 2024-08-23 20:20:49

随机盐的目的是确保如果数据库表泄露,简单的彩虹表无法解密密码。如果每条记录都有自己的盐,则每一行都需要一个新的彩虹表。

你的洗牌方法很好。要点是每条记录的盐都是不同的,这样单个彩虹表就不会危及整个密码表。盐的“强度”并不那么重要。

The purpose of random salts is to ensure that a simple rainbow table won't work to decrypt the passwords, should the database table be leaked. If each record has its own salt, a new rainbow table would be needed for every single row.

Your shuffling approach is fine. The main point is for the salts to be DIFFERENT for each record, so that a single rainbow table won't compromise the whole table of passwords. The "strength" of the salts isn't as important.

凉城 2024-08-23 20:20:49

当顺序很重要时,打乱字符并取出前 12 个字符的方法相当于选取(不重复)12 个字符。你有 36!/(36-12)! ~~ 2^59 种可能的方法。

如果您从 36 个字母的集合中选取所有 12 个元素(可能有重复),则有 36^12 ~~2^62 种可能的方法。

因此,在您使用的方法中,最终会得到大约 59 位的熵。我想说它对于任何应用程序来说都足够了,并且只提供比选择重复元素少 8 倍的组合。

The method of shuffling characters and taking the first 12 is equivalent to picking (without repetitions) 12 characters when the order matters. You have 36!/(36-12)! ~~ 2^59 possible ways of doing this.

If you pick all 12 elements (with possible repetitions) from the set of 36 letters, there are 36^12 ~~2^62 possible ways of doing it.

So in the method you used you end up with around 59 bits of entropy. I would say it's sufficient for any application and gives only 8 times less combinations that picking elements with repetitions.

永言不败 2024-08-23 20:20:49

盐的强度取决于您对安全的担忧程度。您可以简单地用用户名加盐(不是很强),或者您可以像您一样为每个用户生成唯一的盐。

如果您真的担心,您还可以创建一个加密密钥,并对其中的每一个进行加密。

显然,你添加的越多,它就会越强大。这完全取决于您对安全的担心程度。

你可以尝试在盐中添加一些特殊字符,它会更坚固。

How strong a salt is all depends on how worried you are about security. You could simply salt it with the username (not very strong,) or you could generate a unique salt for each user, as you did.

If you're really worried, you could also create an encryption key, and encrypt each of these.

The more you add to it, the stronger it will, be, obviously. It's all just how worried about security you are.

You could try adding some special characters to that salt and it would be a lot stronger.

灯角 2024-08-23 20:20:49

12 个字符或更多字符的盐长度很难破解,但您也可以通过使用其他字符(即大写字母和特殊字符)轻松地使盐更强。

您已经对哈希值加盐并确保每个记录都有自己的盐,这是非常重要< /a>.

Salt lengths of 12 characters or more are difficult to crack but you can easily make your salts stronger by using other characters too i.e. upper case letters and special characters.

You are already salting your hash and ensuring each record has it's own individual salt which is very important.

静谧幽蓝 2024-08-23 20:20:49

任何足够随机的盐都是“足够”强的。盐的随机性和字符数越多,哈希值就越好,但任何长度为几个字符且随机的东西都可以。

以下是一些有关密码安全性的有趣链接:

Any sufficiently random salt is strong "enough". The more randomness and more characters your salt has, the better for the hash, but anything that's several characters long and random works.

Here's some interesting links on password security:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文