首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在random_bytes() Laravel PHP 7.0中打开源代码设备

无法在random_bytes() Laravel PHP 7.0中打开源代码设备
EN

Stack Overflow用户
提问于 2017-06-06 14:24:48
回答 1查看 497关注 0票数 0

我访问了很多论坛,但我找不到解决我的问题的最佳方案。在laravel 5中,我有这样的错误:

代码语言:javascript
复制
Cannot open source device in random_bytes() : 
Exception in Str.php line 243:
Cannot open source device
in Str.php line 243
at random_bytes('25') in Str.php line 243
at Str::randomBytes('25') in Str.php line 227
at Str::random('25') in Store.php line 197
at Store->generateSessionId() in Store.php line 173

该str.php位于: httpdocs/vendor/laravel/framework/src/Illuminate/Support/Str.php中:

代码语言:javascript
复制
/**
 * Generate a more truly "random" alpha-numeric string.
 *
 * @param  int  $length
 * @return string
 */
public static function random($length = 16)
{
    $string = '';

    while (($len = strlen($string)) < $length) {
        $size = $length - $len;

        $bytes = static::randomBytes($size);

        $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
    }

    return $string;
}

/**
 * Generate a more truly "random" bytes.
 *
 * @param  int  $length
 * @return string
 */
public static function randomBytes($length = 16)
{
    return random_bytes($length);
}

我使用php7。我也用openssl_random_pseudo_bytes()修改了random_bytes,这是正常的,但是我有另一个错误,框架不能为密码生成哈希。所以我认为openssl_random_bytes不是最好的解决方案。

如果有人能帮忙的话。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-06-06 14:36:18

来自random_bytes documentation

此函数使用的随机性来源如下:

  • 在Windows上,将始终使用»CryptGenRandom()。在Linux上,将使用»getrandom(2)
  • 系统调用(如果可用)。
  • 在其他平台上,将使用/dev/urandom
  • 如果上述来源均不可用,则将抛出异常。

所以你的案子是最后一个了。这不是代码的问题,而是服务器设置的问题。环境是什么?托管、云、虚拟服务器、本地计算机?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44382744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档