added AES 256 to upload and download

This commit is contained in:
oxidiert
2025-08-11 13:53:31 +02:00
parent 385e7cd72e
commit 0052d1908a
3 changed files with 65 additions and 18 deletions

View File

@ -23,25 +23,16 @@ object DatabaseUploader {
fun uploadEncryptedDatabase(context: Context) {
CoroutineScope(Dispatchers.IO).launch {
try {
Log.d("UPLOAD", "Upload gestartet")
val dbFile = context.getDatabasePath(DB_NAME)
Log.d("UPLOAD", "Pfad zur DB: ${dbFile.absolutePath}, existiert: ${dbFile.exists()}")
if (!dbFile.exists()) return@launch
if (!dbFile.exists()) {
Log.e("UPLOAD", "Datenbankdatei existiert nicht.")
return@launch
}
// Verschlüsselte Datei erstellen
val encryptedFile = File(context.cacheDir, ENCRYPTED_FILE_NAME)
AES256Helper.encryptFile(dbFile, encryptedFile)
// Datenbankinhalt vor Upload ausgeben (Hex-String)
logFileContentAsHex(dbFile, "UPLOAD")
Log.d("UPLOAD", "Datei verschlüsselt: ${encryptedFile.absolutePath}")
val exportFile = File(context.cacheDir, ENCRYPTED_FILE_NAME)
dbFile.copyTo(exportFile, overwrite = true)
Log.d("UPLOAD", "Datei kopiert: ${exportFile.absolutePath}")
uploadFile(context, exportFile, dbFile)
uploadFile(context, encryptedFile, dbFile)
} catch (e: Exception) {
Log.e("UPLOAD", "Fehler beim Hochladen der DB", e)
@ -49,6 +40,7 @@ object DatabaseUploader {
}
}
private fun uploadFile(context: Context, file: File, originalDbFile: File) {
val requestBody = MultipartBody.Builder()
.setType(MultipartBody.FORM)