cake_wallet/lib/entities/get_encryption_key.dart

20 lines
661 B
Dart
Raw Permalink Normal View History

import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cw_core/cake_hive.dart';
2020-01-04 19:31:52 +00:00
Future<List<int>> getEncryptionKey(
{required String forKey, required SecureStorage secureStorage}) async {
final stringifiedKey = await secureStorage.read(key: 'transactionDescriptionsBoxKey');
2020-01-04 19:31:52 +00:00
List<int> key;
if (stringifiedKey == null) {
key = CakeHive.generateSecureKey();
2020-01-04 19:31:52 +00:00
final keyStringified = key.join(',');
String storageKey = 'transactionDescriptionsBoxKey';
await secureStorage.write(key: storageKey, value: keyStringified);
2020-01-04 19:31:52 +00:00
} else {
key = stringifiedKey.split(',').map((i) => int.parse(i)).toList();
2020-01-04 19:31:52 +00:00
}
return key;
}