{"id":13607809,"url":"https://github.com/a1573595/SecuritySharedPreferences","last_synced_at":"2025-04-12T14:31:13.484Z","repository":{"id":108545493,"uuid":"302895315","full_name":"a1573595/SecuritySharedPreferences","owner":"a1573595","description":"A small SharedPreferences wrapper and cryptographic android library power by Kotlin.","archived":false,"fork":false,"pushed_at":"2021-10-30T09:00:42.000Z","size":193,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T12:12:41.161Z","etag":null,"topics":["aes","android","base64","keystore","kotlin","rsa","security","sharedpreferences"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a1573595.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"securitysharedpreferences/.gitignore","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-10-10T12:20:25.000Z","updated_at":"2022-03-05T00:12:42.000Z","dependencies_parsed_at":"2023-08-22T06:15:27.209Z","dependency_job_id":null,"html_url":"https://github.com/a1573595/SecuritySharedPreferences","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1573595%2FSecuritySharedPreferences","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1573595%2FSecuritySharedPreferences/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1573595%2FSecuritySharedPreferences/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1573595%2FSecuritySharedPreferences/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a1573595","download_url":"https://codeload.github.com/a1573595/SecuritySharedPreferences/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581102,"owners_count":21128103,"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":["aes","android","base64","keystore","kotlin","rsa","security","sharedpreferences"],"created_at":"2024-08-01T19:01:21.785Z","updated_at":"2025-04-12T14:31:13.038Z","avatar_url":"https://github.com/a1573595.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"*Read this in other languages: [English](README.md), [中文](README.zh-tw.md).*\n\n# SecuritySharedPreferences\nA small SharedPreferences wrapper and cryptographic android library power by Kotlin.\n\n⚡ Kotlin powered.\n\n🚀 Easy to use.\n\n🔒 Protect data (Android KeyStore + AES256 SIV / + AES256 GCM).\n\n🧪 Support Unit test.\n\n## Difference\nDifference between the android SharedPreference and SecuritySharedPreferences library.\n* SharedPreference\n```\n\u003c?xml version='1.0' encoding='utf-8' standalone='yes' ?\u003e\n\u003cmap\u003e\n    \u003cstring name=\"Account\"\u003eABC@gmail.com\u003c/string\u003e\n\u003c/map\u003e\n```\n\n* SecuritySharedPreferences\n```\n\u003c?xml version='1.0' encoding='utf-8' standalone='yes' ?\u003e\n\u003cmap\u003e\n    \u003cstring name=\"AWT/LySwiIhTyjEtGKZ9kQ0t6n30XnNbLft3/g==\"\u003eAVQneV9aILgdLAT+OYJowJYWzeRktEj7gsttnTN4bLXMa690QKYnBWq1MuwnFpYAhjV/Gna2axuvqw==\u003c/string\u003e\n\u003c/map\u003e\n```\n\n## Supported Android Versions\n- Android 5.1 Lollipop(API level 21) or higher.\n\n## Gradle\n```groovy\nallprojects {\n    repositories {\n    ...\n    \n    maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n```groovy\ndependencies {\n    implementation 'com.github.a1573595:SecuritySharedPreferences:2.0.3'\n\t\n    // Optional - Unit test\n    testImplementation 'junit:junit:4.13.2'\n    testImplementation 'androidx.arch.core:core-testing:2.1.0'\n    testImplementation 'androidx.test:core-ktx:1.4.0'\n    testImplementation 'androidx.test.ext:junit-ktx:1.1.3'\n    testImplementation 'org.robolectric:robolectric:4.6.1'\n}\n```\n\n## Usage\nDefine your SecuritySharedPreferences and add the parameters to be stored.\n```kotlin\nclass DefaultPreferences(context: Context) :\n    SecuritySharedPreferences(context, context.packageName) {\n    // Add your stored parameter...\n    var userName by PreferencesData\u003cString\u003e(\"Name\", \"Chien\")\n\n    var email by PreferencesData\u003cString\u003e(\"Email\", \"\")\n\n    var address by PreferencesData\u003cString\u003e(\"Address\", \"\")\n\n    var age by PreferencesData\u003cInt\u003e(\"Age\", 25)\n\n    var height by PreferencesData\u003cFloat\u003e(\"Height\", 1.75f)\n}\n```\n\nOr you can customize the KeyStore alias, SharedPreferences name and mode.\n```kotlin\nclass CustomPreferences(context: Context) :\n    SecuritySharedPreferences(context, \"${context.packageName}.custom\") {\n    // Add your stored parameter...\n}\n```\n\nInitialization SecuritySharedPreferences instance, easy to get and set stored value.\n```kotlin\nval preferencesManager = DefaultPreferences(this)\n\n// get value from SecuritySharedPreferences\nval email = preferencesManager.email\n\n// save value into SecuritySharedPreferences\npreferencesManager.email = \"ABC@gmail.com\"\n```\n\n## Unit test\n```kotlin\n@RunWith(AndroidJUnit4::class)\nclass SecuritySharedPreferencesTest {\n    companion object {\n        @JvmStatic\n        @BeforeClass\n        fun beforeClass() {\n            FakeAndroidKeyStore.setup\n        }\n    }\n\n    private val preferences: CustomPreferences =\n        CustomPreferences(ApplicationProvider.getApplicationContext())\n\n\t...\n}\n```\n\n## Reference\n[AndroidKeyStore](https://github.com/joetsaitw/AndroidKeyStore)\n\n[Testing Jetpack Security with Robolectric](https://proandroiddev.com/testing-jetpack-security-with-robolectric-9f9cf2aa4f61)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa1573595%2FSecuritySharedPreferences","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa1573595%2FSecuritySharedPreferences","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa1573595%2FSecuritySharedPreferences/lists"}