/** * @return $this */ public function encryptArchive() { $key = $this->config['crypt-key']; $fileCrypt = new FileCrypt(); $source = $this->getFileName(); $destination = $this->getFileName() . '.encrypted'; $encryptResult = $fileCrypt->encryptFileChunks($source, $destination, $key); if ($encryptResult) { $this->setFilename($destination); } return $this; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws DecryptException */ protected function execute(InputInterface $input, OutputInterface $output) { $key = $input->getOption('key'); if (empty($key)) { throw new DecryptException('Missing encrypt key'); } $file = $input->getArgument('file'); $path = realpath($file); if (!$path || !is_readable($path)) { throw new DecryptException(sprintf('File "%s" not found or not readable', $file)); } $finfo = new \SplFileInfo($path); if ($finfo->getExtension() !== 'encrypted') { throw new DecryptException(sprintf('File "%s" must be with ".encrypted" extension', $file)); } $fileCrypt = new FileCrypt(); $result = $fileCrypt->decryptFileChunks($path, str_replace('.encrypted', '', $path), $key); if ($result) { $output->writeln(sprintf('File "%s" decrypt successful', $file)); } else { $output->writeln(sprintf('Error with encrypting file "%s"', $file)); } return; }