diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index 91bdff6bf..4d5257409 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -47,7 +47,7 @@ class Configuration { Future generateAndSaveKey(String passphrase) async { // Create a master key - final key = CryptoUtil.generateMasterKey(); + final key = CryptoUtil.generateKey(); // Derive a key from the passphrase that will be used to encrypt and // decrypt the master key @@ -55,14 +55,14 @@ class Configuration { final kek = CryptoUtil.deriveKey(utf8.encode(passphrase), kekSalt); // Encrypt the key with this derived key - final encryptedKeyData = await CryptoUtil.encrypt(key, kek); + final encryptedKeyData = CryptoUtil.encryptSync(key, kek); // Hash the passphrase so that its correctness can be compared later final kekHash = await CryptoUtil.hash(kek); // Generate a public-private keypair and encrypt the latter final keyPair = await CryptoUtil.generateKeyPair(); - final encryptedSecretKeyData = await CryptoUtil.encrypt(keyPair.sk, kek); + final encryptedSecretKeyData = CryptoUtil.encryptSync(keyPair.sk, kek); final attributes = KeyAttributes( Sodium.bin2base64(kekSalt), diff --git a/lib/utils/crypto_util.dart b/lib/utils/crypto_util.dart index bcc8f5a34..47d5b327a 100644 --- a/lib/utils/crypto_util.dart +++ b/lib/utils/crypto_util.dart @@ -96,8 +96,7 @@ void chachaDecrypt(Map args) { } class CryptoUtil { - static Future encrypt( - Uint8List source, Uint8List key) async { + static EncryptionResult encryptSync(Uint8List source, Uint8List key) { final nonce = Sodium.randombytesBuf(Sodium.cryptoSecretboxNoncebytes); final args = Map(); @@ -178,7 +177,7 @@ class CryptoUtil { return Computer().compute(chachaDecrypt, param: args); } - static Uint8List generateMasterKey() { + static Uint8List generateKey() { return Sodium.cryptoSecretboxKeygen(); } diff --git a/lib/utils/file_uploader.dart b/lib/utils/file_uploader.dart index 482df1446..4e9d91d30 100644 --- a/lib/utils/file_uploader.dart +++ b/lib/utils/file_uploader.dart @@ -76,7 +76,7 @@ class FileUploader { final encryptedMetadataData = CryptoUtil.encryptChaCha( utf8.encode(jsonEncode(file.getMetadata())), fileAttributes.key); - final encryptedFileKeyData = await CryptoUtil.encrypt( + final encryptedFileKeyData = CryptoUtil.encryptSync( fileAttributes.key, Configuration.instance.getKey(), );