Skip to content

Commit 0eb7651

Browse files
author
Simon Erkelens
committed
Rename the files correctly and append enc to the file instead of replacing the fixed .txt.
1 parent c098295 commit 0eb7651

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

code/AtRestCryptoService.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ public function decrypt($ciphertext, $key = null)
4848
public function encryptFile($file, $key = null)
4949
{
5050
$key = $this->getKey($key);
51-
$encryptedFilename = str_replace('.txt', '.enc', $file->getFullPath());
51+
$encryptedFilename = $file->getFullPath() . '.enc';
5252
try {
5353
File::encryptFile($file->getFullPath(), $encryptedFilename, $key);
5454
unlink($file->getFullPath());
55-
$file->Filename = str_replace('.txt', '.enc', $file->Filename);
56-
$file->Name = str_replace('.txt', '.enc', $file->Name);
55+
$file->Filename = $file->Filename . '.enc';
5756
$file->write();
5857
return $file;
5958
} catch (Exception $e) {
@@ -74,12 +73,12 @@ public function encryptFile($file, $key = null)
7473
public function decryptFile($file, $key = null)
7574
{
7675
$key = $this->getKey($key);
77-
$decryptedFilename = str_replace('.enc', '.txt', $file->getFullPath());
76+
$decryptedFilename = str_replace('.enc', '', $file->getFullPath());
7877
try {
7978
File::decryptFile($file->getFullPath(), $decryptedFilename, $key);
8079
unlink($file->getFullPath());
81-
$file->Filename = str_replace('.enc', '.txt', $file->Filename);
82-
$file->Name = str_replace('.enc', '.txt', $file->Name);
80+
$file->Filename = str_replace('.enc', '', $file->Filename);
81+
$file->Name = str_replace('.enc', '', $file->Name);
8382
$file->write();
8483
return $file;
8584
} catch (Exception $e) {

0 commit comments

Comments
 (0)