Skip to content

Commit

Permalink
add decryption method
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 24, 2021
1 parent e5933e0 commit 5f44465
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/services/encryption_service.dart
Expand Up @@ -14,10 +14,22 @@ class EncryptionService {
final crypt = AesCrypt();
final password = _randomService.getRandomString(16);
crypt.setPassword(password);
logger.i('Password: $password');
crypt.encryptFileSync(
file.path, basenameWithoutExtension(file.path) + '.odin');
final encryptedFilePath =
join(file.parent.path, basenameWithoutExtension(file.path) + '.odin');
crypt.encryptFileSync(file.path, encryptedFilePath);
logger.d('Finished Encryption');
return File(basenameWithoutExtension(file.path) + '.odin');
return File(encryptedFilePath);
}

Future<File> decryptFile(File file, String password) async {
logger.d('Started Deryption');
final crypt = AesCrypt();
crypt.setPassword(password);
file = await file.rename(file.path.replaceAll('.odin', '.aes'));
final decryptedFilePath = crypt.decryptFileSync(file.path,
join(file.parent.path, basenameWithoutExtension(file.path) + '.zip'));
File decryptedFile = File(decryptedFilePath);
logger.d('Finished Decryption');
return decryptedFile;
}
}

0 comments on commit 5f44465

Please sign in to comment.