Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-11 16:43:13 +02:00 коммит произвёл Alper Öztürk
Родитель 123c576399
Коммит 39e9916732
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -548,7 +548,17 @@ public final class EncryptionUtils {
}
public static EncryptedFile encryptFile(Context context, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
File tempEncryptedFile = File.createTempFile(file.getName(), null, context.getFilesDir());
String dirPath = context.getFilesDir().getAbsolutePath() + File.separator + "temp_encrypted_folder";
File tempEncryptedFolder = new File(dirPath);
if (!tempEncryptedFolder.exists()) {
boolean isTempEncryptedFolderCreated = tempEncryptedFolder.mkdirs();
Log_OC.d(TAG, "tempEncryptedFolder created" + isTempEncryptedFolderCreated);
} else {
Log_OC.d(TAG, "tempEncryptedFolder already exists");
}
File tempEncryptedFile = File.createTempFile(file.getName(), null, tempEncryptedFolder);
encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
String authenticationTagString = getAuthenticationTag(cipher);
return new EncryptedFile(tempEncryptedFile, authenticationTagString);
@ -568,7 +578,7 @@ public final class EncryptionUtils {
}
public static void encryptFileWithGivenCipher(File inputFile, File encryptedFile, Cipher cipher) {
try( FileInputStream inputStream = new FileInputStream(inputFile);
try (FileInputStream inputStream = new FileInputStream(inputFile);
FileOutputStream fileOutputStream = new FileOutputStream(encryptedFile);
CipherOutputStream outputStream = new CipherOutputStream(fileOutputStream, cipher)) {
byte[] buffer = new byte[4096];