gpt4 book ai didi

php - 使用 bin2hex(random_bytes($str)) 在密码学上是安全的吗?

转载 作者:行者123 更新时间:2023-12-02 00:37:50 24 4
gpt4 key购买 nike

我找到了这个问题的不同答案,但没有一个问及加密安全性。

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com