Explicitly state the sync nature of the encryption API
This commit is contained in:
parent
86b60fd487
commit
bae5c9bf7d
3 changed files with 6 additions and 7 deletions
|
@ -47,7 +47,7 @@ class Configuration {
|
|||
|
||||
Future<KeyAttributes> 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),
|
||||
|
|
|
@ -96,8 +96,7 @@ void chachaDecrypt(Map<String, dynamic> args) {
|
|||
}
|
||||
|
||||
class CryptoUtil {
|
||||
static Future<EncryptionResult> encrypt(
|
||||
Uint8List source, Uint8List key) async {
|
||||
static EncryptionResult encryptSync(Uint8List source, Uint8List key) {
|
||||
final nonce = Sodium.randombytesBuf(Sodium.cryptoSecretboxNoncebytes);
|
||||
|
||||
final args = Map<String, dynamic>();
|
||||
|
@ -178,7 +177,7 @@ class CryptoUtil {
|
|||
return Computer().compute(chachaDecrypt, param: args);
|
||||
}
|
||||
|
||||
static Uint8List generateMasterKey() {
|
||||
static Uint8List generateKey() {
|
||||
return Sodium.cryptoSecretboxKeygen();
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue