SecuredStorage class
SecuredStorage 是一个基于 flutter_secure_storage 封装的安全存储类, 提供了基于凯撒加密算法(Caesar Cipher)的轻量级加解密功能, 同时支持单向加密模式(one-way encryption),用于防止解密(类似于哈希处理)。
参数说明:
- passphrase 用于派生加密的偏移量(shift)
- isOneWayEncryption 如果为 true,则启用单向加密,仅可写入,无法解密读取
使用场景:
可用于保存轻度敏感信息(如 token、用户 ID), 注意:此方案为教学/调试级安全,不适用于高强度加密需求。
Constructors
- SecuredStorage.new({required String passphrase, bool? isOneWayEncryption = false})
-
构造函数,用于创建 SecuredStorage 实例
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isOneWayEncryption → bool?
-
是否启用不可逆的加密(无法解密),适用于 token/hash 场景
final
- passphrase → String?
-
传入的密码短语,用于生成 Caesar Cipher 的位移量
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → FlutterSecureStorage
-
内部的安全存储实例,使用 flutter_secure_storage 实现平台原生加密存储
final
Methods
-
cipher(
String text, int shift, {bool decrypt = false}) → String -
恺撒密码
加/解密算法
-
delete(
String key) → Future< void> - 删除指定键的数据
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
String key) → Future< String?> - 读取并解密指定键的数据
-
readAll(
) → Future< Map< String, String> > - 读取所有存储项(以键值对 Map 返回)
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
String key, String newValue) → Future< void> - 更新指定键的值(覆盖旧值)
-
write(
String key, String value) → Future< void> - 加密并写入数据到安全存储中
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited