diff --git a/src/Illuminate/Encryption/EncryptionServiceProvider.php b/src/Illuminate/Encryption/EncryptionServiceProvider.php index 7b1143562063..ad365becc4eb 100755 --- a/src/Illuminate/Encryption/EncryptionServiceProvider.php +++ b/src/Illuminate/Encryption/EncryptionServiceProvider.php @@ -18,12 +18,7 @@ public function register() $this->app->singleton('encrypter', function ($app) { $config = $app->make('config')->get('app'); - // If the key starts with "base64:", we will need to decode the key before handing - // it off to the encrypter. Keys may be base-64 encoded for presentation and we - // want to make sure to convert them back to the raw bytes before encrypting. - if (Str::startsWith($key = $config['key'], 'base64:')) { - $key = base64_decode(substr($key, 7)); - } + $key = $config['key']; if (is_null($key) || $key === '') { throw new RuntimeException( @@ -31,6 +26,13 @@ public function register() ); } + // If the key starts with "base64:", we will need to decode the key before handing + // it off to the encrypter. Keys may be base-64 encoded for presentation and we + // want to make sure to convert them back to the raw bytes before encrypting. + if (Str::startsWith($key, 'base64:')) { + $key = base64_decode(substr($key, 7)); + } + return new Encrypter($key, $config['cipher']); }); }