Skip to content

Commit

Permalink
Move empty key detection above starts_with check
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed May 11, 2017
1 parent 3a4fdd0 commit 8f1a966
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Illuminate/Encryption/EncryptionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ 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(
'The application encryption key is missing. Run php artisan key:generate to generate it.'
);
}

// 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']);
});
}
Expand Down

0 comments on commit 8f1a966

Please sign in to comment.