{"id":16401727,"url":"https://github.com/xaldarof/encrypted-shared-preferences","last_synced_at":"2025-09-30T11:30:22.119Z","repository":{"id":65214455,"uuid":"588115746","full_name":"xaldarof/encrypted-shared-preferences","owner":"xaldarof","description":"Perfect for developers prioritizing security, Encrypted Shared Preferences integrates effortlessly into your projects, offering peace of mind and enhancing data privacy. Safeguard your app's data with this essential encryption solution","archived":false,"fork":false,"pushed_at":"2025-01-06T16:50:35.000Z","size":445,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T17:49:37.252Z","etag":null,"topics":["encryption","flutter","key","library","observable","reactive","sharedpreferences","stream"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaldarof.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-12T11:11:08.000Z","updated_at":"2025-01-06T16:50:39.000Z","dependencies_parsed_at":"2023-02-10T22:45:13.631Z","dependency_job_id":"6ffbc1fa-9afb-4b01-a596-6214b0b0de00","html_url":"https://github.com/xaldarof/encrypted-shared-preferences","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaldarof%2Fencrypted-shared-preferences","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaldarof%2Fencrypted-shared-preferences/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaldarof%2Fencrypted-shared-preferences/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaldarof%2Fencrypted-shared-preferences/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaldarof","download_url":"https://codeload.github.com/xaldarof/encrypted-shared-preferences/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234730964,"owners_count":18878166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encryption","flutter","key","library","observable","reactive","sharedpreferences","stream"],"created_at":"2024-10-11T05:44:00.628Z","updated_at":"2025-09-30T11:30:22.113Z","avatar_url":"https://github.com/xaldarof.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"Shared preferences are a simple key-value storage mechanism that can be used to store small amounts\nof data. However, since shared preferences are stored in plain text, it is not suitable for storing\nsensitive information. To address this issue, you can use AES encryption to encrypt the data before\nsaving it to shared preferences.\n\nTo use shared preferences with AES encryption support, you can add this package to your project as\ndependency.\n\n[Open pub.dev](https://pub.dev/packages/encrypt_shared_preferences)\n\nLegacy EncryptedSharedPreferences\n\n```dart\nvoid main() async {\n  final key = \"\";\n  await EncryptedSharedPreferences.initialize(key: key);\n  var sharedPref = EncryptedSharedPreferences.getInstance();\n\n  await sharedPref.setString(\n      'user_token', 'xxxxxxxxxxxx', notify: true); ////notify = true by default\n\n  sharedPref.getString('user_token'); //xxxxxxxxxxxx\n\n  await sharedPref.setInt('age', 99, notify: true); //notify = true by default\n\n  sharedPref.getInt('age', defaultValue: 1001); //99\n\n  await sharedPref.setDouble('pi', 3.14, notify: true); //notify = true by default\n\n  sharedPref.getDouble('pi'); //3.14\n\n  await sharedPref.setBool('isPremium', true, notify: true); //notify = true by default\n\n  sharedPref.getBool('isPremium'); //true\n\n  await sharedPref.setStringList(\"stringList\", [\"apple\", \"orange\", \"boom\"]);\n\n  sharedPref.getStringList(\"stringList\");\n\n  await sharedPref.remove('user_token', notify: true); //notify = true by default\n\n  await sharedPref.clear(notify: true); //notify = true by default\n\n  await sharedPref.reload();\n\n  final badKeys = {\n    \"key1\"\n        \"key2\"\n  };\n  await sharedPref.removeWhere((key, value) =\u003e badKeys.contains(key));\n\n  sharedPref.observe(key: 'token').listen((event) {\n    // event = key\n    print(event);\n  });\n\n  sharedPref.observeSet(keys: {'key1', 'key2', 'keyN'}).listen((event) {\n    // event = key\n    print(event);\n  });\n}\n```\n\nEncryptedSharedPreferencesAsync\n\n```dart\nvoid main() async {\n  final key = \"\";\n  await EncryptedSharedPreferencesAsync.initialize(key: key);\n  var sharedPref = EncryptedSharedPreferencesAsync.getInstance();\n\n  await sharedPref.setString(\n      'user_token', 'xxxxxxxxxxxx', notify: true); ////notify = true by default\n\n  await sharedPref.getString('user_token'); //xxxxxxxxxxxx\n\n  await sharedPref.setInt('age', 99, notify: true); //notify = true by default\n\n  await sharedPref.getInt('age', defaultValue: 1001); //99\n\n  await sharedPref.setDouble('pi', 3.14, notify: true); //notify = true by default\n\n  await sharedPref.getDouble('pi'); //3.14\n\n  await sharedPref.setBool('isPremium', true, notify: true); //notify = true by default\n\n  await sharedPref.getBool('isPremium'); //true\n\n  await sharedPref.setStringList(\"stringList\", [\"apple\", \"orange\", \"boom\"]);\n\n  await sharedPref.getStringList(\"stringList\");\n\n  await sharedPref.remove('user_token', notify: true); //notify = true by default\n\n  await sharedPref.clear(notify: true); //notify = true by default\n\n  await sharedPref.reload();\n\n  final badKeys = {\n    \"key1\"\n        \"key2\"\n  };\n  await sharedPref.removeWhere((key, value) =\u003e\n      badKeys.contains(key));\n\n  sharedPref.observe(key: 'token').listen((event) {\n    // event = key\n    print(event);\n  });\n\n  sharedPref.observeSet(keys: {'key1', 'key2', 'keyN'}).listen((event) {\n    // event = key\n    print(event);\n  });\n}\n```\n\n[Shared builder] Here is example of how to use SharedBuilder widget\n\n```dart\nclass _MyAppState extends State\u003cMyApp\u003e {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      home: Scaffold(\n        body: SharedBuilder(\n          listenKeys: const {\"key1\", \"key2\"}, //Optional\n          builder: (EncryptedSharedPreferences encryptedSharedPreferences, String? updatedKey) {\n            return Text(\"value : ${encryptedSharedPreferences.getString(\"key1\")}\");\n          },\n        ),\n        floatingActionButton: FloatingActionButton(\n          onPressed: () async {\n            EncryptedSharedPreferences.getInstance()\n                .setString('key1', 'dataValue');\n            Future.delayed(const Duration(seconds: 3), () {\n              EncryptedSharedPreferences.getInstance()\n                  .setString('key2', 'dataValue');\n            });\n          },\n        ),\n      ),\n    );\n  }\n}\n\n```\n\n[Shared builder async] Here is example of how to use SharedBuilder widget\n\n```dart\nclass _MyAppState extends State\u003cMyApp\u003e {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      home: Scaffold(\n        body: SharedBuilderAsync(\n          listenKeys: const {\"key1\", \"key2\"}, //Optional\n          builder: (EncryptedSharedPreferencesAsync encryptedSharedPreferences,\n              String? updatedKey) {\n            return Text(\"value : $updatedKey\");\n          },\n        ),\n        floatingActionButton: FloatingActionButton(\n          onPressed: () async {\n            EncryptedSharedPreferencesAsync.getInstance()\n                .setString('key1', 'dataValue');\n            Future.delayed(const Duration(seconds: 3), () {\n              EncryptedSharedPreferencesAsync.getInstance()\n                  .setString('key2', 'dataValue');\n            });\n          },\n        ),\n      ),\n    );\n  }\n}\n\n```\n\nAlso you can add custom external encryptor\n\n```dart\nclass CustomEncryptor extends IEncryptor {\n  @override\n  String decrypt(String key, String encryptedData) {\n    //decryption logic\n  }\n\n  @override\n  String encrypt(String key, String plainText) {\n    //encryption logic\n  }\n}\n\nvoid main() {\n  final key = \"\";\n  await EncryptedSharedPreferences.initialize(key: key, encryptor: CustomEncryptor());\n  var sharedPref = EncryptedSharedPreferences.getInstance();\n}\n```\n\nDevTools extension for inspecting values\n\n![alt text](https://github.com/xaldarof/encrypted-shared-preferences/blob/main/screenshots/devtools.png?raw=true)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaldarof%2Fencrypted-shared-preferences","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaldarof%2Fencrypted-shared-preferences","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaldarof%2Fencrypted-shared-preferences/lists"}