EncryptedSharedPreferences 是一個 Flutter 插件,透過在將資料儲存至裝置儲存空間之前進行加密,安全地儲存鍵值對。它擴展了 SharedPreferences 的功能,提供端對端加密,確保如權杖、密碼或使用者偏好等敏感資訊免於未經授權的存取。該插件使用強大的加密演算法,並與 Android、iOS、Web、macOS、Windows 及 Linux 平台無縫整合。適用於需要安全的本機資料持久化且不暴露憑證的應用程式。
適用情境
儲存驗證權杖
安全保存用戶偏好
保護敏感的應用程式資料
安全會話管理
加密 API 金鑰
受監管環境中的本地資料保護
主要特色
端對端加密
跨平台支援
與 SharedPreferences 的無縫整合
安全金鑰管理
支援所有主要的桌面和行動平台
易於使用的 API
適合對象
處理敏感用戶數據的應用程式
注重合規性的應用程式
認證系統
注重隱私的應用程式
以行動裝置為先的應用程式
安全設定儲存
使用建議
需要正確的金鑰處理
由於加密可能導致效能開銷
不適用於大型資料集
依賴於平台特定的安全功能
需要仔細實現以避免金鑰洩露
由於加密格式,除錯功能有限
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Encrypted Shared Preferences
This plugin stores Shared Preferences as encrypted values. It is decrypted when retrieved. You could use this side by side with regular Shared Preferences.
/// Clears all values, including those you saved using regular Shared Preferences.
encryptedSharedPreferences.clear().then((bool success) {
if (success) {
print('success');
} else {
print('fail');
}
});
Reload
encryptedSharedPreferences.reload();
Optional: Pass custom SharedPreferences instance
/// You can pass a custom SharedPreferences instance (e.g. A newer version of SharedPreferences)final prefs = awaitSharedPreferences.getInstance();
EncryptedSharedPreferences encryptedSharedPreferences = EncryptedSharedPreferences(prefs: prefs);
Access internal SharedPreferences instance
// You can access the internal SharedPreferences instance to invoke methods not exposed by regular EncryptedSharedPreferencesSharedPreferences instance = await encryptedSharedPreferences.getInstance();
int counter = 1;
/// Access SharedPreferences' setInt methodawait instance.setInt('counter', counter);
Modes of operation
Default mode is SIC AESMode.sic, you can override it using the mode named parameter: