update method

Future<void> update(
  1. String key,
  2. String newValue
)

更新指定键的值(覆盖旧值)

如果键不存在将抛出异常。若启用 one-way 模式,将以相同加密逻辑写入新值。

Implementation

Future<void> update(String key, String newValue) async {
  final exists = await storage.containsKey(key: key);
  if (!exists) {
    throw Exception("Key '$key' does not exist. Cannot update.");
  }

  final cipheredValue = cipher(
    newValue,
    passphrase!.length,
    decrypt: isOneWayEncryption!,
  );

  await storage.write(key: key, value: cipheredValue);
  debugPrint('SecuredStorage [UPDATE] $key: $newValue -> $cipheredValue');
}