{"id":18780150,"url":"https://github.com/ericksumargo/pin","last_synced_at":"2025-10-09T06:33:39.582Z","repository":{"id":73392312,"uuid":"247421828","full_name":"ErickSumargo/Pin","owner":"ErickSumargo","description":"Built over Jetpack's EncryptedSharedPreferences API with less verbose syntax, efficient read/write mechanism, complex object and null default value support with compile time safety","archived":false,"fork":false,"pushed_at":"2020-04-17T10:00:45.000Z","size":459,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-21T06:39:02.011Z","etag":null,"topics":["coroutines","cryptography","jetpack","kotlin","sharedpreferences"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/ErickSumargo.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-03-15T07:36:20.000Z","updated_at":"2021-09-14T15:53:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"a57b5d79-f9e7-441f-b931-5a900a1a539b","html_url":"https://github.com/ErickSumargo/Pin","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ErickSumargo/Pin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErickSumargo%2FPin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErickSumargo%2FPin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErickSumargo%2FPin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErickSumargo%2FPin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ErickSumargo","download_url":"https://codeload.github.com/ErickSumargo/Pin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErickSumargo%2FPin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000830,"owners_count":26082950,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["coroutines","cryptography","jetpack","kotlin","sharedpreferences"],"created_at":"2024-11-07T20:25:04.460Z","updated_at":"2025-10-09T06:33:39.566Z","avatar_url":"https://github.com/ErickSumargo.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pin [ ![Download](https://api.bintray.com/packages/ericksumargo/Bael/com.bael.pin/images/download.svg?version=2.0) ](https://bintray.com/ericksumargo/Bael/com.bael.pin/2.0/link)\nHere's a look how our session data is stored using Android's normal [SharedPreferences](https://developer.android.com/training/data-storage/shared-preferences) API:\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cimg src=\"images/normal.png\"\u003e\n\u003cp align=\"center\"\u003eFlipper - Normal/Plain Mode\u003c/p\u003e\n\u003cbr/\u003e\n\nIt's plain. With some proper steps, it's easily getting exposed. [[See How-to](https://resources.infosecinstitute.com/android-hacking-security-part-9-insecure-local-storage-shared-preferences/#gref)]\n\u003cbr/\u003e\n\u003cbr/\u003e\nThankfully, Android Jetpack's team comes with new [EncryptedSharedPreferences](https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences) API to support data encryption. \n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cimg src=\"images/encrypted.png\"\u003e\n\u003cp align=\"center\"\u003eFlipper - Encrypted Mode\u003c/p\u003e\n\u003cbr/\u003e\nAs normal SharedPreferences, we still need to deal with some tedious boilerplates, e.g., instantiating, mechanism to read, and write a preference. \n\u003cbr/\u003e\n\u003cbr/\u003e\nThis is the background why \u003cb\u003ePin\u003c/b\u003e comes to surface. Pin with additional features helps to abstract away those boilerplates so you can 100% just focus on business.\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## Features\nPin provides:\n- Encrypted/Normal mode\n- Less verbose syntax\n- Efficient read/write mechanism with coroutine\n- Support complex object and null default value\n- Compile time safety\n\n## Download\nSince EncryptedSharedPreferences requires \u003cb\u003eminSdkVersion 23+\u003c/b\u003e, you should take note if your app supports it.\n```groovy\nimplementation 'com.bael:pin:${latestRelease}'\n```\nElse, you could use the normal version instead:\n```groovy\nimplementation 'com.bael:pin:${latestRelease}-normal'\n```\n\n## Setup\nInit Pin in the `onCreate` method of your application class\n```kotlin\noverride fun onCreate() {\n    super.onCreate()\n    // Set useEncryptedMode as false to switch back into normal mode\n    Pin.init(context = this, \"YOUR_PREFERENCES_FILE_NAME\", useEncryptedMode = true)\n}\n```\n\n## Usage\n```kotlin\nclass MainActivity : AppCompatActivity() {\n\n    // Less Verbose\n    private var object1: Int by Pin(key = \"object1_key\", defaultValue = -1)\n\n    // Support Complex Object\n    private var object2: Movie by Pin(key = \"object2_key\", defaultValue = Movie())\n\n    // Support Nullability\n    private var object3: Movie? by Pin(key = \"object3_key\", defaultValue = null)\n\n    /** \n      * Compile Time Safety\n      * Below lint will be error, the type should be declared as nullable since the default set null\n      * private var object4: Movie by Pin(key = \"object4_key\", defaultValue = null)\n      */\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n\n        /**\n         * Read\n         * 1. Read it like a normal variable\n         * 2. Seriously, that's all\n         */\n        println(object1)\n        println(object2)\n        println(object3)\n\n        /**\n         * Write\n         * 1. Update it like normal variable assignment\n         * 2. Seriously, that's all\n         */\n        object1 = 1\n        object2 = Movie(id = 2)\n        object3 = Movie(id = 3)\n    }\n    \n    override fun onDestroy() {\n        // Remove a preference value associated with certain key\n        Pin.clear(\"object1_key\")\n        // Remove all values from preferences\n        Pin.clear()\n        \n        super.onDestroy()\n    }\n}\n```\n\n## License\n```\nCopyright 2020 Erick Sumargo\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericksumargo%2Fpin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericksumargo%2Fpin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericksumargo%2Fpin/lists"}