hiveKeys function

Future<List<int>> hiveKeys()

Implementation

Future<List<int>> hiveKeys() async {
  const FlutterSecureStorage ss = FlutterSecureStorage();

  const AndroidOptions aOptions = AndroidOptions(
    encryptedSharedPreferences: true,
  );

  const IOSOptions iOptions = IOSOptions(
    accessibility: KeychainAccessibility.first_unlock,
  );
  String? stringKey = await ss.read(
    key: 'boxKey',
    aOptions: aOptions,
    iOptions: iOptions,
  );
  late List<int> hiveKey;
  if (stringKey != null) {
    hiveKey = stringKey.codeUnits;
  } else {
    hiveKey = Hive.generateSecureKey();
    final Uint8List bytes = Uint8List.fromList(hiveKey);
    stringKey = String.fromCharCodes(bytes);
    // if (Platform.isAndroid) {
    await ss.write(
      key: 'boxKey',
      value: stringKey,
      aOptions: aOptions,
      iOptions: iOptions,
    );
    // } else {
    //   await _ss.write(key: 'boxKey', value: stringKey, iOptions: iOptions);
    // }
  }
  return hiveKey;
}