Use the explicit sync-decrypt API

This commit is contained in:
Vishnu Mohandas 2020-10-11 04:10:18 +05:30
parent bd879263f0
commit 50a67acb75
3 changed files with 11 additions and 16 deletions

View file

@ -88,7 +88,7 @@ class Configuration {
if (!correctPassphrase) {
throw Exception("Incorrect passphrase");
}
final key = await CryptoUtil.decrypt(
final key = CryptoUtil.decryptSync(
Sodium.base642bin(attributes.encryptedKey),
kek,
Sodium.base642bin(attributes.keyDecryptionNonce));

View file

@ -110,17 +110,15 @@ class CryptoUtil {
}
static Future<Uint8List> decrypt(
Uint8List cipher, Uint8List key, Uint8List nonce,
{bool background = false}) async {
Uint8List cipher,
Uint8List key,
Uint8List nonce,
) async {
final args = Map<String, dynamic>();
args["cipher"] = cipher;
args["nonce"] = nonce;
args["key"] = key;
if (background) {
return Computer().compute(cryptoSecretboxOpenEasy, param: args);
} else {
return cryptoSecretboxOpenEasy(args);
}
return Computer().compute(cryptoSecretboxOpenEasy, param: args);
}
static Uint8List decryptSync(

View file

@ -174,11 +174,8 @@ Future<io.File> _downloadAndDecrypt(File file, BaseCacheManager cacheManager,
return null;
}
logger.info("File downloaded: " + file.uploadedFileID.toString());
await CryptoUtil.decryptFile(
encryptedFilePath,
decryptedFilePath,
Sodium.base642bin(file.fileDecryptionHeader),
await decryptFileKey(file));
await CryptoUtil.decryptFile(encryptedFilePath, decryptedFilePath,
Sodium.base642bin(file.fileDecryptionHeader), decryptFileKey(file));
logger.info("File decrypted: " + file.uploadedFileID.toString());
io.File(encryptedFilePath).deleteSync();
final fileExtension = extension(file.title).substring(1).toLowerCase();
@ -203,7 +200,7 @@ Future<io.File> _downloadAndDecryptThumbnail(File file) async {
"_thumbnail.decrypted";
return Dio().download(file.getThumbnailUrl(), temporaryPath).then((_) async {
final encryptedFile = io.File(temporaryPath);
final thumbnailDecryptionKey = await decryptFileKey(file);
final thumbnailDecryptionKey = decryptFileKey(file);
final data = CryptoUtil.decryptChaCha(
encryptedFile.readAsBytesSync(),
thumbnailDecryptionKey,
@ -219,8 +216,8 @@ Future<io.File> _downloadAndDecryptThumbnail(File file) async {
});
}
Future<Uint8List> decryptFileKey(File file) {
return CryptoUtil.decrypt(
Uint8List decryptFileKey(File file) {
return CryptoUtil.decryptSync(
Sodium.base642bin(file.encryptedKey),
Configuration.instance.getKey(),
Sodium.base642bin(file.keyDecryptionNonce));