1 | <?php |
||
2 | /** |
||
3 | * EncryptService.php |
||
4 | * Copyright (c) 2018 [email protected] |
||
5 | * |
||
6 | * This file is part of Firefly III. |
||
7 | * |
||
8 | * Firefly III is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation, either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * Firefly III is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | declare(strict_types=1); |
||
23 | |||
24 | namespace FireflyIII\Services\Internal\File; |
||
25 | |||
26 | use FireflyIII\Exceptions\FireflyException; |
||
27 | |||
28 | /** |
||
29 | * Class EncryptService |
||
30 | */ |
||
31 | class EncryptService |
||
32 | { |
||
33 | /** |
||
34 | * @param string $file |
||
35 | * @param string $key |
||
36 | * |
||
37 | * @throws FireflyException |
||
38 | */ |
||
39 | public function encrypt(string $file, string $key): void |
||
40 | { |
||
41 | if (!file_exists($file)) { |
||
42 | throw new FireflyException(sprintf('File "%s" does not seem to exist.', $file)); |
||
43 | } |
||
44 | $content = file_get_contents($file); |
||
45 | $content = Crypt::encrypt($content); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
46 | $newName = sprintf('%s.upload', $key); |
||
47 | $path = storage_path('upload') . '/' . $newName; |
||
48 | |||
49 | file_put_contents($path, $content); |
||
50 | } |
||
51 | |||
52 | } |
||
53 |