getKeys method

Set<String> getKeys()

Implementation

Set<String> getKeys() {
  if (_config.type == StorageType.sharedPreferences) {
    if (_config.enableEncryption) {
      // Filter and decrypt keys
      return _prefs!
          .getKeys()
          .where((key) => key.startsWith('enc_'))
          .map((key) {
            try {
              final encoded = key.substring(4);
              final decoded = utf8.decode(base64Url.decode(encoded.padRight(
                (encoded.length + 3) ~/ 4 * 4,
                '=',
              )));
              return CryptoUtils.decryptAES(
                encryptedData: decoded,
                userKey: _encryptionKey!,
              );
            } catch (e) {
              return null;
            }
          })
          .where((key) => key != null)
          .cast<String>()
          .toSet();
    } else {
      return _prefs!.getKeys();
    }
  } else {
    return _hiveBox!.keys.map((e) => e.toString()).toSet();
  }
}