/**
  * Get the proper encrypter instance for the given key and cipher.
  *
  * @param  string  $key
  * @param  string  $cipher
  * @return mixed
  *
  * @throws \RuntimeException
  */
 protected function getEncrypterForKeyAndCipher($key, $cipher)
 {
     if (Encrypter::supported($key, $cipher)) {
         return new Encrypter($key, $cipher);
     } elseif (McryptEncrypter::supported($key, $cipher)) {
         return new McryptEncrypter($key, $cipher);
     } else {
         throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
     }
 }
 private static function getEncrypter()
 {
     $config = static::getEncrypterVariables();
     $key = $config['key'];
     $cipher = $config['cipher'];
     if (Encrypter::supported($key, $cipher)) {
         return new Encrypter($key, $cipher);
     } elseif (McryptEncrypter::supported($key, $cipher)) {
         return new McryptEncrypter($key, $cipher);
     } else {
         throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
     }
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('encrypter', function ($app) {
         $config = $app->make('config')->get('app');
         $key = $config['key'];
         $cipher = $config['cipher'];
         if (Encrypter::supported($key, $cipher)) {
             return new Encrypter($key, $cipher);
         } elseif (McryptEncrypter::supported($key, $cipher)) {
             return new McryptEncrypter($key, $cipher);
         } else {
             throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
         }
     });
 }
예제 #4
0
 /**
  * Determine if the given key and cipher combination is valid.
  *
  * @param string $key
  * @param string $cipher
  * @return bool 
  * @static 
  */
 public static function supported($key, $cipher)
 {
     return \Illuminate\Encryption\Encrypter::supported($key, $cipher);
 }
예제 #5
0
 protected function setupEncryptionKey($force = false)
 {
     $validKey = false;
     $cipher = Config::get('app.cipher');
     $keyLength = $this->getKeyLength($cipher);
     $randomKey = $this->getRandomKey($cipher);
     if ($force) {
         $key = $randomKey;
     } else {
         $this->line(sprintf('Enter a new value of %s characters, or press ENTER to use the generated key', $keyLength));
         while (!$validKey) {
             $key = $this->ask('Application key', $randomKey);
             $validKey = Encrypter::supported($key, $cipher);
             if (!$validKey) {
                 $this->error(sprintf('[ERROR] Invalid key length for "%s" cipher. Supplied key must be %s characters in length.', $cipher, $keyLength));
             }
         }
     }
     $this->writeToConfig('app', ['key' => $key]);
     $this->info(sprintf('Application key [%s] set successfully.', $key));
 }