douluoyou9876 2016-07-29 01:12
浏览 357
已采纳

mcrypt_encrypt():Mcrypt初始化失败

I downloaded example Laravel 5 project and try to test on my local machine. But I can see errors like following:

ErrorException in User.php line 115:
mcrypt_encrypt(): Mcrypt initialisation failed

1. in User.php line 115
2. at HandleExceptions->handleError('4096', 'mcrypt_encrypt(): Mcrypt     initialisation failed', 'C:\wamp\www
oj\app\Models\User.php', '115',     array('pure_string' => 'asdfasdf', 'USER_PASSWORD_SALT' => null, 'key' => '', 'iv_size' => '8', 'iv' => 'ЎZo\S '))
3. at mcrypt_encrypt('blowfish', '', 'asdfasdf', 'ecb', 'ЎZo\S ') in User.php line 115
4. at User::encrypthash('asdfasdf') in Registrar.php line 36
5. at Registrar->create(array('_token' => '7oIiiOAtUu4Quc949u7SmtcDlI5a0zo0AEJgBA3S', 'name' => 'Bob', 'email' => 'bob@example.com', 'password' => 'asdfasdf', 'password_confirmation' => 'asdfasdf')) in AuthenticatesAndRegistersUsers.php line 50
6. at AuthController->postRegister(object(Request))</li>
...

User.php

        ...  
108.    public static function encrypthash($pure_string) {
109.        //xulianwhocreatenoj
110.        $USER_PASSWORD_SALT = env('USER_PASSWORD_SALT');
111.        $key = pack('H*', $USER_PASSWORD_SALT);
112.        $pure_string = trim($pure_string);
113.        $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
114.        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
115.        $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
116.        return base64_encode($encrypted_string);
117.    }
        ...

I do not have deep knowledge about PHP nor mcrypt_encrypt() function. Please help me to get rid of this.

  • 写回答

2条回答 默认 最新

  • dptiq46022 2016-07-29 01:22
    关注

    The problem on line 115 is that your encryption key is just an empty string.

    $key is empty because two lines up, you have:

    $USER_PASSWORD_SALT = env('USER_PASSWORD_SALT');
    

    The problem there is that env('USER_PASSWORD_SALT') is empty so there is no salt. If you fix that, your function will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分