. */ declare(strict_types=1); namespace FireflyIII\Services\Internal\File; use Crypt; use FireflyIII\Exceptions\FireflyException; use Illuminate\Contracts\Encryption\EncryptException; use Log; /** * Class EncryptService */ class EncryptService { /** * @param string $file * @param string $key * * @throws FireflyException */ public function encrypt(string $file, string $key): void { if (!file_exists($file)) { throw new FireflyException(sprintf('File "%s" does not seem to exist.', $file)); } $content = file_get_contents($file); try { $content = Crypt::encrypt($content); } catch (EncryptException $e) { $message = sprintf('Could not encrypt file: %s', $e->getMessage()); Log::error($message); throw new FireflyException($message); } $newName = sprintf('%s.upload', $key); $path = storage_path('upload') . '/' . $newName; file_put_contents($path, $content); } }