我找到了这个问题的不同答案,但没有一个问及加密安全性。
在 PHP 中使用 bin2hex(random_bytes($str))
是否加密安全?它会降低安全性或唯一性吗?
最佳答案
The documentation for random_bytes
表示函数
Generates an arbitrary length string of cryptographic random bytes that are suitable for cryptographic use, such as when generating salts, keys or initialization vectors.
因此 PHP 开发人员相信它已经足够好了。输入应该是字节数,而不是字符串:
string random_bytes ( int $length )
bin2hex
对生成数据的加密适用性没有影响。特别是,它不能将您的随机字节“拉伸(stretch)”成更多的随机字节。如果您需要 $n
字节的随机数据,请使用 random_bytes($n)
。
关于php - 使用 bin2hex(random_bytes($str)) 在密码学上是安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48628985/