for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Stidges\LaravelSodiumEncryption;
use RuntimeException;
use Illuminate\Support\Str;
use Illuminate\Support\ServiceProvider;
class EncryptionServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
$this->app->singleton('encrypter.sodium', function ($app) {
$config = $app->make('config')->get('app');
if (Str::startsWith($key = $this->key($config), 'base64:')) {
$key = base64_decode(substr($key, 7));
}
return new Encrypter($key);
});
$this->app->alias('encrypter.sodium', Encrypter::class);
* Extract the encryption key from the given configuration.
* @param array $config
* @return string
* @throws \RuntimeException
protected function key(array $config)
return tap($config['key'], function ($key) {
if (empty($key)) {
throw new RuntimeException(
'No application encryption key has been specified.'
);