diff --git a/lib/services/encryption_service.dart b/lib/services/encryption_service.dart index 1323f38..98f7e09 100644 --- a/lib/services/encryption_service.dart +++ b/lib/services/encryption_service.dart @@ -9,15 +9,15 @@ import 'package:path/path.dart'; class EncryptionService { final RandomService _randomService = locator(); - Future encryptFile({ - required File file, - }) async { + Future encryptFile(File file) async { logger.d('Started Encryption'); final crypt = AesCrypt(); - crypt.setPassword(_randomService.getRandomString(16)); + final password = _randomService.getRandomString(16); + crypt.setPassword(password); + logger.i('Password: $password'); crypt.encryptFileSync( file.path, basenameWithoutExtension(file.path) + '.odin'); - logger.d('Finished Zipping Files'); + logger.d('Finished Encryption'); return File(basenameWithoutExtension(file.path) + '.odin'); } } diff --git a/lib/services/file_service.dart b/lib/services/file_service.dart index 4ea5c1a..7f5c68c 100644 --- a/lib/services/file_service.dart +++ b/lib/services/file_service.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:file_picker/file_picker.dart'; +import 'package:odin/services/encryption_service.dart'; import 'package:odin/services/github_service.dart'; import 'package:odin/services/locator.dart'; import 'package:odin/services/zip_service.dart'; @@ -9,6 +10,7 @@ import 'package:path/path.dart'; class FileService { final _githubService = locator(); final _zipService = locator(); + final _encrytionService = locator(); bool loading = false; bool processing = false; String? fileLink; @@ -25,9 +27,10 @@ class FileService { processing = true; List files = result.paths.map((path) => File(path!)).toList(); final zippedFile = await _zipService.zipFile(fileToZips: files); + final encryptedFile = await _encrytionService.encryptFile(zippedFile); zipfileName = basename(zippedFile.path); processing = false; - _path = await _githubService.uploadFileAnonymous(zippedFile); + _path = await _githubService.uploadFileAnonymous(encryptedFile); loading = false; } else { // User canceled the picker @@ -46,9 +49,10 @@ class FileService { final List fileToZips = urls.map((e) => File(e.toFilePath())).toList(); final zippedFile = await _zipService.zipFile(fileToZips: fileToZips); + final encryptedFile = await _encrytionService.encryptFile(zippedFile); zipfileName = basename(zippedFile.path); processing = false; - _path = await _githubService.uploadFileAnonymous(zippedFile); + _path = await _githubService.uploadFileAnonymous(encryptedFile); loading = false; } else { _path = null;