在PHP中生成一个盐 [英] Generating a salt in PHP

查看:1241
本文介绍了在PHP中生成一个盐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中生成加密安全的32位字节盐的最佳方法是什么,而不依赖于典型PHP安装中很少包含的库?

What's the best way to generate a cryptographically secure 32 bytes salt in PHP, without depending on libraries seldom included in typical PHP installations?

mt_rand 被认为不够安全,但我还没有找到替换的建议。一篇文章建议从 / dev / random 中读取,但不仅仅是在Windows上不能工作;

After some googling I discovered that mt_rand is not considered secure enough, but I haven't found a suggestion for a replacement. One article suggested reading from /dev/random but not only this won't work on windows; it is also very slow.

我希望在安全性和速度之间有一个合理的平衡(即,它不应该需要20秒生成512字节,例如 / dev / random 通常会这样)

I want a reasonable balance between security and speed (ie, it shouldn't take 20 seconds to generate 512 bytes, like /dev/random usually does)

推荐答案


注意 mcrypt 已在PHP 7.1中弃用。 跳到最新答案

Note: mcrypt has been deprecated in PHP 7.1. Skip to the up-to-date answer.

您可能需要查看 mcrypt_create_iv()

You might want to take a look at the documentation (and comments) for mcrypt_create_iv().

这篇关于在PHP中生成一个盐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆