搜索插件、代码仓与 APP 分类

插件详情v1.0.5

get_secure_storage

get_storage 的安全版本,这是一个用 Dart 完全编写的快速、轻量且同步的键值存储

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1520
喜欢数
29
Pub 分数
130

安装插件

flutter pub add get_secure_storage

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

GetSecureStorage 是基于 GetStorage 构建的、安全的同步键值存储解决方案,专为 Dart 应用程序设计。它提供跨多个平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)的加密数据持久化功能。与标准存储不同,它在保存数据前对值进行加密,从而保护敏感信息,非常适合存储凭据、令牌或私有用户数据。该包在保持其前身轻量级和高性能的同时,增加了强大的安全特性。

适合场景

  • 存储用户身份验证令牌
  • 保存加密的 API 密钥
  • 持久化敏感用户偏好
  • 保护会话数据
  • 保护登录凭据
  • 启用安全的离线数据存储

主要特点

  • 存储数据的端到端加密
  • 同步 API,用于可预测的执行
  • 跨平台兼容性
  • 轻量且快速的性能
  • 简单的键值接口
  • 基于 GetStorage 构建

适合对象

  • 需要安全数据持久化的应用
  • 注重简单和速度的开发者
  • 处理敏感用户信息的项目
  • 具有离线需求的移动和桌面应用程序
  • 使用 Flutter 且依赖项最少的团队

使用建议

  • 不适用于大型数据集
  • 加密会带来轻微的性能开销
  • 需要谨慎管理密钥
  • 仅限基本的键值操作
  • 无内置的数据迁移支持
  • 取决于底层的 GetStorage 实现

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

get_secure_storage

A cryptography Secure version of GetStorage originally written by Jonny Borges (https://github.com/jonataslaw/get_storage).

GetSecureStorage is a secure, fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and is based on the Cryptography dart package.

The cryptography library used is https://pub.dev/packages/cryptography

The algorithm used is 128bit AES-CTR with MAC sha256

Supports Android, iOS, Web, Mac, Linux, and Windows. Can store String, int, double, Map and List

Add to your pubspec:
dependencies:
  get_secure_storage:
Install it

You can install packages from the command line:

with Flutter:

$  flutter packages get
Import it

Now in your Dart code, you can use:

import 'package:get_secure_storage/get_secure_storage.dart';
Initialize storage driver with await:
main() async {
  await GetSecureStorage.init(password: 'strongpassword');
  runApp(App());
}
use GetSecureStorage through an instance or use directly GetSecureStorage().read('key')
final box = GetSecureStorage(password: 'strongpassword');
To write information you must use write :
box.write('quote', 'GetSecureStorage is the best');
To read values you use read:
print(box.read('quote'));
// out: GetSecureStorage is the best

To remove a key, you can use remove:
box.remove('quote');
To listen changes you can use listen:
Function? disposeListen;
disposeListen = box.listen((){
  print('box changed');
});
If you subscribe to events, be sure to dispose them when using:
disposeListen?.call();
To listen changes on key you can use listenKey:
box.listenKey('key', (value){
  print('new key is $value');
});
To erase your container:
box.erase();
If you want to create different containers, simply give it a name. You can listen to specific containers, and also delete them.
GetSecureStorage g = GetSecureStorage(container:'MyStorage', password: 'strongpassword');
To initialize specific container:
await GetSecureStorage.init(container:'MyStorage', password: 'strongpassword');

SharedPreferences Implementation

class MyPref {
  static final _otherBox = () => GetSecureStorage(container:'MyPref', password: 'strongpassword');

  final username = ''.val('username');
  final age = 0.val('age');
  final price = 1000.val('price', getBox: _otherBox);

  // or
  final username2 = ReadWriteValue('username', '');
  final age2 = ReadWriteValue('age', 0);
  final price2 = ReadWriteValue('price', '', _otherBox);
}

...

void updateAge() {
  final age = 0.val('age');
  // or 
  final age = ReadWriteValue('age', 0, () => box);
  // or 
  final age = Get.find<MyPref>().age;

  age.val = 1; // will save to box
  final realAge = age.val; // will read from box
}

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。