简体   繁体   English

mcrypt_encrypt():Mcrypt初始化失败

[英]mcrypt_encrypt(): Mcrypt initialisation failed

I downloaded example Laravel 5 project and try to test on my local machine. 我下载了Laravel 5项目示例,并尝试在本地计算机上进行测试。 But I can see errors like following: 但是我可以看到类似以下的错误:

ErrorException in User.php line 115: User.php第115行中的ErrorException:
mcrypt_encrypt(): Mcrypt initialisation failed mcrypt_encrypt():Mcrypt初始化失败

1. in User.php line 115
2. at HandleExceptions->handleError('4096', 'mcrypt_encrypt(): Mcrypt     initialisation failed', 'C:\wamp\www\noj\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 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. 我对PHP和mcrypt_encrypt()函数都不了解。 Please help me to get rid of this. 请帮我摆脱这个。

The problem on line 115 is that your encryption key is just an empty string. 115行的问题是您的加密密钥只是一个空字符串。

$key is empty because two lines up, you have: $key为空,因为有两行,您有:

$USER_PASSWORD_SALT = env('USER_PASSWORD_SALT');

The problem there is that env('USER_PASSWORD_SALT') is empty so there is no salt. 问题在于env('USER_PASSWORD_SALT')为空,因此没有盐。 If you fix that, your function will work. 如果您解决此问题,您的功能将起作用。

Run php artisan key:generate on your command line (which should located on your Laravel project root) to refresh your application key. 在命令行上运行php artisan key:generate (应位于Laravel项目根目录下)以刷新应用程序密钥。

Then clear your cache and sessions and try again. 然后清除缓存和会话,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM