搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。