/** * @param int $length * @param bool $bin2hex * @return string */ public function generate($length, $bin2hex = false) { $hash = Strings::random($length); if (!empty($bin2hex)) { return bin2hex($hash); } return $hash; }
/** * @param DirectoriesInterface $directories * @param FilesInterface $files * @param EncrypterConfig $config */ public function perform(DirectoriesInterface $directories, FilesInterface $files, EncrypterConfig $config) { $envFilename = $directories->directory('root') . '.env'; if (!$files->exists($envFilename)) { $this->writeln("<fg=red>'env.' file does not exists, unable to sek encryption key.</fg=red>"); } $files->write($envFilename, str_replace($config->getKey(), Strings::random(32), $files->read($envFilename))); $this->writeln("<info>Encryption key has been successfully updated.</info>"); }
/** * Unique wrapper. * * @return string */ private static function createWrapper() { $wrapper = '(~' . Strings::random(64) . '~)'; if (in_array($wrapper, self::$wrappers)) { return self::createWrapper(); } return self::$wrappers[] = $wrapper; }