diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index ee5e3279b..7c3330386 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -1,3 +1,4 @@ +import 'package:encrypt/encrypt.dart'; import 'package:photos/utils/crypto_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -75,7 +76,7 @@ class Configuration { } void generateAndSaveKey(String passphrase) async { - final key = CryptoUtil.createCryptoRandomString(); + final key = SecureRandom(32).base64; await _preferences.setString(keyKey, CryptoUtil.encrypt(key, passphrase)); } diff --git a/lib/utils/crypto_util.dart b/lib/utils/crypto_util.dart index f6e823456..3e711825e 100644 --- a/lib/utils/crypto_util.dart +++ b/lib/utils/crypto_util.dart @@ -1,16 +1,6 @@ -import 'dart:convert'; -import 'dart:math'; - import 'package:encrypt/encrypt.dart'; class CryptoUtil { - static final Random _random = Random.secure(); - - static String createCryptoRandomString([int length = 32]) { - var values = List.generate(length, (i) => _random.nextInt(256)); - return base64Url.encode(values); - } - static String encrypt(String plainText, String key) { final encrypter = Encrypter(AES(Key.fromUtf8(key))); return encrypter.encrypt(plainText).base64;