Bladeren bron

Decrypt fileKey in background worker when decrypting thumbnail

ashilkn 2 jaren geleden
bovenliggende
commit
2704001d65
2 gewijzigde bestanden met toevoegingen van 25 en 1 verwijderingen
  1. 24 0
      lib/utils/file_download_util.dart
  2. 1 1
      lib/utils/thumbnail_util.dart

+ 24 - 0
lib/utils/file_download_util.dart

@@ -1,6 +1,7 @@
 import 'dart:io' as io;
 import 'dart:typed_data';
 
+import "package:computer/computer.dart";
 import 'package:dio/dio.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
@@ -70,3 +71,26 @@ Uint8List getFileKey(ente.File file) {
       CollectionsService.instance.getCollectionKey(file.collectionID!);
   return CryptoUtil.decryptSync(encryptedKey, collectionKey, nonce);
 }
+
+Future<Uint8List> getFileKeyUsingBgWorker(ente.File file) async {
+  final collectionKey =
+      CollectionsService.instance.getCollectionKey(file.collectionID!);
+  return await Computer.shared().compute(
+    _decryptFileKey,
+    param: <String, dynamic>{
+      "encryptedKey": file.encryptedKey,
+      "keyDecryptionNonce": file.keyDecryptionNonce,
+      "collectionKey": collectionKey,
+    },
+  );
+}
+
+Uint8List _decryptFileKey(Map<String, dynamic> args) {
+  final encryptedKey = CryptoUtil.base642bin(args["encryptedKey"]);
+  final nonce = CryptoUtil.base642bin(args["keyDecryptionNonce"]);
+  return CryptoUtil.decryptSync(
+    encryptedKey,
+    args["collectionKey"],
+    nonce,
+  );
+}

+ 1 - 1
lib/utils/thumbnail_util.dart

@@ -157,7 +157,7 @@ Future<void> _downloadAndDecryptThumbnail(FileDownloadItem item) async {
   if (!_uploadIDToDownloadItem.containsKey(file.uploadedFileID)) {
     return;
   }
-  final thumbnailDecryptionKey = getFileKey(file);
+  final thumbnailDecryptionKey = await getFileKeyUsingBgWorker(file);
   var data = await CryptoUtil.decryptChaCha(
     encryptedThumbnail,
     thumbnailDecryptionKey,