Skip to content

Commit

Permalink
Ensured hive key errors are handeled correctly
Browse files Browse the repository at this point in the history
(cherry picked from commit 7110e62)
  • Loading branch information
Clon1998 committed Feb 20, 2024
1 parent acd60af commit 75b049f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/app_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,22 @@ Future<Uint8List> _hiveKey() async {
var secureStorage = const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
);
const nonEncSharedPrefSecureStorage = FlutterSecureStorage();
const nonEncSharedPrefSecureStorage = FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: false),
);

Uint8List? encryptionKey;
try {
encryptionKey = await secureStorage.read(key: keyName).then((value) => value?.let(base64Decode));
} on PlatformException catch (e) {
logger.e('Error while reading hive_key from secure storage', e);
encryptionKey = await nonEncSharedPrefSecureStorage.read(key: keyName).then((value) => value?.let(base64Decode));
encryptionKey = await nonEncSharedPrefSecureStorage
.read(key: keyName)
.then((value) => value?.let(base64Decode))
.onError((error, stackTrace) {
logger.e('Error while reading hive_key from non-encryptedSharedPreferences', error, stackTrace);
return null;
});
await nonEncSharedPrefSecureStorage.delete(key: keyName);
await secureStorage.write(
key: keyName,
Expand Down

0 comments on commit 75b049f

Please sign in to comment.