{"id":15939535,"url":"https://github.com/afiqiqmal/sharedchamber","last_synced_at":"2025-10-18T16:01:48.316Z","repository":{"id":58278848,"uuid":"85935414","full_name":"afiqiqmal/SharedChamber","owner":"afiqiqmal","description":"Android Secure SharedPreferences Using Facebook Conceal Encryption","archived":false,"fork":false,"pushed_at":"2020-09-08T03:04:09.000Z","size":624,"stargazers_count":95,"open_issues_count":5,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-24T17:47:34.432Z","etag":null,"topics":["android","android-secure-sharedpreferences","conceal","concealsharedpreference-android","decryption","encryption","facebook","hacktoberfest","java","proguard","secure-android-sharedpreferences","sharedpreferences","simple"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afiqiqmal.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":null,"support":null}},"created_at":"2017-03-23T10:12:33.000Z","updated_at":"2024-01-31T22:11:13.000Z","dependencies_parsed_at":"2022-08-31T23:11:34.661Z","dependency_job_id":null,"html_url":"https://github.com/afiqiqmal/SharedChamber","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afiqiqmal%2FSharedChamber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afiqiqmal%2FSharedChamber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afiqiqmal%2FSharedChamber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afiqiqmal%2FSharedChamber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afiqiqmal","download_url":"https://codeload.github.com/afiqiqmal/SharedChamber/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237049902,"owners_count":19246942,"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":["android","android-secure-sharedpreferences","conceal","concealsharedpreference-android","decryption","encryption","facebook","hacktoberfest","java","proguard","secure-android-sharedpreferences","sharedpreferences","simple"],"created_at":"2024-10-07T06:04:58.287Z","updated_at":"2025-10-18T16:01:43.263Z","avatar_url":"https://github.com/afiqiqmal.png","language":"Java","readme":"# SharedChamber Android\n[![](https://jitpack.io/v/afiqiqmal/SharedChamber.svg)](https://jitpack.io/#afiqiqmal/SharedChamber) [![API](https://img.shields.io/badge/API-16%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=16)\n[![](https://img.shields.io/badge/Project-Java-brightgreen.svg)](https://github.com/afiqiqmal/SharedChamber)\n[![](https://img.shields.io/badge/Project-Kotlin-yellowgreen.svg)](https://github.com/afiqiqmal/SharedChamber-Kotlin)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/mhi9388?locale.x=en_US)\n\n\n\u003cb\u003eProject :\u003c/b\u003e SharedChamber on top of SharedPreferences using [Facebook Conceal](http://facebook.github.io/conceal/)\u003cbr\u003e\n\u003cb\u003eDescription \u003c/b\u003e\n\u003cbr\u003e\nConceal provides a set of Java APIs to perform cryptography on Android. It was designed to be able to encrypt large files on disk in a fast and memory efficient manner. Implementation on SharedPreferences of Android would be great data Encryption and Decryption. Currently supported Facebook Conceal V2.0 \n\n## Installation\n\nGradle\n```gradle\ndependencies {\n        implementation 'com.github.afiqiqmal:SharedChamber:2.5.1'\n\n        //or\n\n        implementation 'com.github.afiqiqmal:SharedChamber:2.5.1' {\n            exclude group: 'com.google.code.gson', module: 'gson'\n        }\n}\n```\n\nMaven\n```maven\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.github.afiqiqmal\u003c/groupId\u003e\n\t\u003cartifactId\u003eSharedChamber\u003c/artifactId\u003e\n\t\u003cversion\u003e2.5.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n#### First of All\n\nit needed to first init in Application class in `oncreate` method or on Base Activity Class. or everything is not working =D\n```java\nSharedChamber.initChamber(this);\n```\n\n\nPermission need to use in your project. Please Allow it first if you need to use file save, or it will affect `.putImage` and `.putFile` method\n```xml\n\u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/\u003e\n\u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/\u003e\n```\n\n##### Initialize\n```java\nSharedChamber sharedChamber = new SharedChamber.ChamberBuilder(this)\n        //.useThisPrefStorage(\"Android_Prefs\")\n        .setChamberType(ChamberType.KEY_256)  //ChamberType.KEY_256 or ChamberType.KEY_128\n        .enableCrypto(true,true) //param 1 - enable value encryption , param 2 - enable key encryption\n        .enableKeyPrefix(true, \"walaoweh\") //1- if false, prefix will be ignore\n        .setPassword(\"Android\") //default value - BuildConfig.APPLICATION_ID\n        .setFolderName(\"testing\") //create Folder for data stored: default is - \"conceal_path\"\n        .setPrefListener(this) // listen to data changes \n        .buildChamber();\n\n*setFolderName - folder will be hidden. To see, enable show hidden folder in storage\n               - data stored here only images and files\n               - sharedpreferences are not store here\n               - created folder by default YOURSTORAGE/.conceal_path/images\n\n               - for images - in folder /images\n               - for files - in folder /files\n```\n\n##### Save data\n\n```java\nsharedChamber.put(KEY,\"Hello\");\nsharedChamber.put(KEY,1000000);\nsharedChamber.put(KEY,100.00);\nsharedChamber.put(KEY,new byte[]);\nsharedChamber.put(KEY,new Map\u003cString,String\u003e());\n...\n...\n```\n\nfor complex object might need use `putModel` which use gson\n```\nsharedChamber.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, \"users.json\"), User.class));\nsharedChamber.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, \"users.json\"), new TypeToken\u003cArrayList\u003cUsers\u003e\u003e(){}.getType()));\n```\n\n\nFiles and Images\n```\n// Files and Images will be encrypted\n// prefix of this encrypted images and files start with \"conceal_enc_\";\nFile getFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+\"/testing.pdf\");\nsharedChamber.putFile(KEY,getFile,boolean deleteOldFiles);\n// deleteOldFiles - true or false.. true - will delete choosen file and move to new path\n\n//put images\nsharedChamber.put(KEY, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));\nsharedChamber.put(KEY, File file);\nsharedChamber.putDrawable(KEY, Drawable ID);\n...\n...\n```\n\n##### \u003cb\u003eFor Method Chaining\u003c/b\u003e\n```java\nnew SharedChamber.Editor(\"PREFIX\") // optional - get default from global prefix\n                .put(KEY,\"Hello\")\n                .put(KEY,1000000)\n                .put(KEY,true)\n                .put(KEY,new byte[])\n                .put(KEY,getFile,boolean deleteOldFiles);\n                .put(KEY, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))\n                .put(KEY, imageFile)\n                .put(KEY,STRING_LIST)\n                .put(KEY,FLOAT_LIST)\n\t\t.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, \"users.json\"), User.class));\n                ...\n                ...\n                .apply(); //.commit();\n```\n\n##### \u003cb\u003eGet total data\u003c/b\u003e\n```java\nSystem.out.println(sharedChamber.getPrefsSize());\n```\n\n##### \u003cb\u003eGet all sharedpreferences data\u003c/b\u003e\n```java\nMap\u003cString,String\u003e getAll = sharedChamber.getEverythingInChamberInMap();\n```\n\n##### \u003cb\u003eGet all sharedpreferences data in List String\u003c/b\u003e\n```java\nList\u003cString\u003e getAll = sharedChamber.getEverythingInChamberInList();\n```\n\n##### \u003cb\u003eGet all encrypted Files inside created folder\u003c/b\u003e\n```java\nList\u003cCryptoFile\u003e getFiles = sharedChamber.getAllChamberFiles();\n```\n\n##### \u003cb\u003eFetching data\u003c/b\u003e\n\n```java\nsharedChamber.getString(KEY);\nsharedChamber.getString(KEY,DEFAULT_VALUE);\nsharedChamber.getInt(KEY);\nsharedChamber.getInt(KEY,DEFAULT_VALUE);\nsharedChamber.getDouble(KEY);\nsharedChamber.getDouble(KEY,DEFAULT_VALUE);\n\n//using gson\nsharedChamber.getModel(KEY, User.class).toString();\nsharedChamber.getModel(KEY, new TypeToken\u003cArrayList\u003cTask\u003e\u003e(){}.getType()).toString();\n.....\n\nBitmap bitmap = sharedChamber.getImage(KEY);   //return String path\nFile enc_file = sharedChamber.getFile(KEY,true);    //return File\n// this getImage and getFile will totally decrypted selected file/image. You need to encrypt it back.\n// just call sharedChamber.putImage(KEY,bitmap); or sharedChamber.putFile(KEY,enc_file,true);\n........\n```\n\n##### \u003cb\u003eClear key and SharedPreferences\u003c/b\u003e\n\n```java\nsharedChamber.destroyChamber(); //clear key\nsharedChamber.clearChamber(); // clear all\n\nsharedChamber.remove(KEY1,KEY2,KEY3,KEY4) //String... keys\nsharedChamber.removeFile(KEY); //delete assosiate file (images and files) return boolean\n```\n\n##### \u003cb\u003eCheck if key exists\u003c/b\u003e\n```java\nsharedChamber.contains(KEY); // return boolean\n```\n\n##### \u003cb\u003eGet SharedPreferences\u003c/b\u003e\n```java\nsharedChamber.getChamber();\n```\n\n##### \u003cb\u003eListener Data Changes\u003c/b\u003e\n```java\npublic class BaseActivity extends AppCompatActivity implements OnDataChamberChangeListener{\n    ....\n    @Override\n    public void onDataChange(String key,String value) {\n         //code here\n    }\n}\n```\n\n##### \u003cb\u003eEasier Save User Detail Preferences\u003c/b\u003e\n```java\nnew SharedChamber.UserChamber()\n.setFirstName(\"Firstname\")\n.setLastName(\"Lasname\")\n.setEmail(\"hello@gmail.com\")\n.....\n.apply(); // need to apply() or commit()\n```\n\nor\n\n```java\nSharedChamber.UserChamber().applyFirstName(\"Firstname\"); //directly apply\nSharedChamber.UserChamber().applyLastName(\"Firstname\"); //directly apply\n```\n\n##### \u003cb\u003eGet User Detail\u003c/b\u003e\n```java\nnew SharedChamber.UserChamber().getFirstName()\nnew SharedChamber.UserChamber().getLastName()\nnew SharedChamber.UserChamber().getEmail()\n.....\n```\n\n##### \u003cb\u003eKey prefix - Apply key with prefix\u003c/b\u003e\n```java\nnew SharedChamber.UserChamber(\"KEY PREFIX\").setFirstName(\"Firstname\").apply();\nnew SharedChamber.UserChamber(\"KEY PREFIX\").setLastName(\"Firstname\").apply();\n```\n\n\n### Extra Usage for Conceal Encryption and Decryption\n\n```java\nSecretChamber secretChamber = new SecretBuilder(this)\n                .setEnableValueEncryption(true) //default true\n                .setEnableKeyEncryption(true) // default true\n                .setChamberType(ChamberType.KEY_256) // ChamberType.KEY_256 or ChamberType.KEY_128\n                .setPassword(\"Mac OSX\")\n                .buildSecret();\n```\n\n##### Hash\n\n```\nsecretChamber.vaultHash(plaintext); // SHA-256\n```\n\n##### Encrypt\n\n```\nsecretChamber.lockVault(test); // encrypt using facebook conceal\nsecretChamber.lockVaultBase(test,4); // encrypt using basic base64 with iteration\nsecretChamber.lockVaultAes(\"Hello World is World Hello Aes Cryption\"); // encrypt using AES\n\n//1-parameter is original location of file..it will move to other location set as in initialization\nsecretChamber.lockVaultFile(File file,boolean deleteOldFile);\n\n```\n\n\n##### Decrypt\n\n```\nsecretChamber.openVault(cipher); // decrypt using facebook conceal\nsecretChamber.openVaultBase(cipher,4); // decrypt using basic base64 with iteration\nsecretChamber.openVaultAes(cipher); // decrypt using AES\n\nsecretChamber.openVaultFile(File file,boolean deleteOldFile);\n```\n\n\n## Proguard\n```proguard\n-keep class com.facebook.crypto.** { *; }\n-keep class com.facebook.jni.** { *; }\n-keepclassmembers class com.facebook.cipher.jni.** { *; }\n-dontwarn com.facebook.**\n```\n\n# TODO\n1. Set Preferences for specific user\n2. Able to switch Preferences between user\n\n\n## Credit\u003cbr\u003e\n[Facebook Conceal](http://facebook.github.io/conceal/) - Conceal provides easy Android APIs for performing fast encryption and authentication of data.\u003cbr\u003e\nDocumentation - [Here](http://facebook.github.io/conceal/)\n\n## Licence\u003cbr\u003e\nopen source project that is licensed under the [MIT license](http://opensource.org/licenses/MIT). Please refer to the license file for more information.\n\n\n\u003ca href=\"https://www.paypal.com/paypalme/mhi9388?locale.x=en_US\"\u003e\u003cimg src=\"https://i.imgur.com/Y2gqr2j.png\" height=\"40\"\u003e\u003c/a\u003e  \n","funding_links":["https://www.paypal.com/paypalme/mhi9388?locale.x=en_US"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafiqiqmal%2Fsharedchamber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafiqiqmal%2Fsharedchamber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafiqiqmal%2Fsharedchamber/lists"}