All Projects → afiqiqmal → Sharedchamber

afiqiqmal / Sharedchamber

Licence: mit
Android Secure SharedPreferences Using Facebook Conceal Encryption

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Sharedchamber

Secure Ls
🔒 Secure localStorage data with high level of encryption and data compression
Stars: ✭ 486 (+406.25%)
Mutual labels:  hacktoberfest, encryption, decryption
Horizoncrypt
Animal Crossing: New Horizons Save Encryptor/Decryptor
Stars: ✭ 36 (-62.5%)
Mutual labels:  encryption, decryption
Iocane
An odorless, tasteless NodeJS crypto library that dissolves instantly in liquid
Stars: ✭ 35 (-63.54%)
Mutual labels:  encryption, decryption
Chef Vault
chef-vault cookbook
Stars: ✭ 63 (-34.37%)
Mutual labels:  hacktoberfest, encryption
Enigma
Enigma cipher tool
Stars: ✭ 13 (-86.46%)
Mutual labels:  encryption, decryption
Java Crypto Utils
Java Cryptographic, Encoding and Hash Utilities
Stars: ✭ 15 (-84.37%)
Mutual labels:  encryption, decryption
Simple Polymorphic Engine Spe32
Simple Polymorphic Engine (SPE32) is a simple polymorphic engine for encrypting code and data. It is an amateur project that can be used to demonstrate what polymorphic engines are.
Stars: ✭ 59 (-38.54%)
Mutual labels:  encryption, decryption
Xjar
Spring Boot JAR 安全加密运行工具,支持的原生JAR。
Stars: ✭ 692 (+620.83%)
Mutual labels:  encryption, decryption
Lazysodium Android
An Android implementation of the Libsodium cryptography library. For the lazy dev.
Stars: ✭ 69 (-28.12%)
Mutual labels:  encryption, decryption
Simon speck ciphers
Implementations of the Simon and Speck Block Ciphers
Stars: ✭ 74 (-22.92%)
Mutual labels:  encryption, decryption
Secure Pref Manager
Secure Preference Manager for android. It uses various Encryption to protect your application's Shared Preferences.
Stars: ✭ 75 (-21.87%)
Mutual labels:  encryption, sharedpreferences
Lyra
A lightweight encryption tool designed for ease of use.
Stars: ✭ 22 (-77.08%)
Mutual labels:  encryption, decryption
Ciphey
⚡ Automatically decrypt encryptions without knowing the key or cipher, decode encodings, and crack hashes ⚡
Stars: ✭ 9,116 (+9395.83%)
Mutual labels:  hacktoberfest, decryption
Hat.sh
encrypt and decrypt files in your browser. Fast, Secure client-side File Encryption and Decryption using the web crypto api
Stars: ✭ 886 (+822.92%)
Mutual labels:  encryption, decryption
Water.css
A drop-in collection of CSS styles to make simple websites just a little nicer
Stars: ✭ 6,666 (+6843.75%)
Mutual labels:  hacktoberfest, simple
Dbfs
Distributed Blockchain-based File Storage 📡
Stars: ✭ 45 (-53.12%)
Mutual labels:  hacktoberfest, encryption
Hybrid Crypto Js
RSA+AES hybrid encryption implementation for JavaScript. Works with Node.js, React Native and modern browsers.
Stars: ✭ 87 (-9.37%)
Mutual labels:  encryption, decryption
Secured Preference Store
A cryptography library and a SharedPreferences wrapper for Android that encrypts the content with 256 bit AES encryption. The Encryption key is securely stored in device's KeyStore.
Stars: ✭ 562 (+485.42%)
Mutual labels:  encryption, sharedpreferences
Ffsend
📬 Easily and securely share files from the command line. A fully featured Firefox Send client.
Stars: ✭ 5,448 (+5575%)
Mutual labels:  hacktoberfest, encryption
Helm Secrets
DEPRECATED A helm plugin that help manage secrets with Git workflow and store them anywhere
Stars: ✭ 1,129 (+1076.04%)
Mutual labels:  encryption, decryption

SharedChamber Android

API Donate

Project : SharedChamber on top of SharedPreferences using Facebook Conceal
Description
Conceal 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

Installation

Gradle

dependencies {
        implementation 'com.github.afiqiqmal:SharedChamber:2.5.1'

        //or

        implementation 'com.github.afiqiqmal:SharedChamber:2.5.1' {
            exclude group: 'com.google.code.gson', module: 'gson'
        }
}

Maven

<dependency>
	<groupId>com.github.afiqiqmal</groupId>
	<artifactId>SharedChamber</artifactId>
	<version>2.5.0</version>
</dependency>

Usage

First of All

it needed to first init in Application class in oncreate method or on Base Activity Class. or everything is not working =D

SharedChamber.initChamber(this);

Permission 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

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Initialize
SharedChamber sharedChamber = new SharedChamber.ChamberBuilder(this)
        //.useThisPrefStorage("Android_Prefs")
        .setChamberType(ChamberType.KEY_256)  //ChamberType.KEY_256 or ChamberType.KEY_128
        .enableCrypto(true,true) //param 1 - enable value encryption , param 2 - enable key encryption
        .enableKeyPrefix(true, "walaoweh") //1- if false, prefix will be ignore
        .setPassword("Android") //default value - BuildConfig.APPLICATION_ID
        .setFolderName("testing") //create Folder for data stored: default is - "conceal_path"
        .setPrefListener(this) // listen to data changes 
        .buildChamber();

*setFolderName - folder will be hidden. To see, enable show hidden folder in storage
               - data stored here only images and files
               - sharedpreferences are not store here
               - created folder by default YOURSTORAGE/.conceal_path/images

               - for images - in folder /images
               - for files - in folder /files
Save data
sharedChamber.put(KEY,"Hello");
sharedChamber.put(KEY,1000000);
sharedChamber.put(KEY,100.00);
sharedChamber.put(KEY,new byte[]);
sharedChamber.put(KEY,new Map<String,String>());
...
...

for complex object might need use putModel which use gson

sharedChamber.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, "users.json"), User.class));
sharedChamber.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, "users.json"), new TypeToken<ArrayList<Users>>(){}.getType()));

Files and Images

// Files and Images will be encrypted
// prefix of this encrypted images and files start with "conceal_enc_";
File getFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/testing.pdf");
sharedChamber.putFile(KEY,getFile,boolean deleteOldFiles);
// deleteOldFiles - true or false.. true - will delete choosen file and move to new path

//put images
sharedChamber.put(KEY, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
sharedChamber.put(KEY, File file);
sharedChamber.putDrawable(KEY, Drawable ID);
...
...
For Method Chaining
new SharedChamber.Editor("PREFIX") // optional - get default from global prefix
                .put(KEY,"Hello")
                .put(KEY,1000000)
                .put(KEY,true)
                .put(KEY,new byte[])
                .put(KEY,getFile,boolean deleteOldFiles);
                .put(KEY, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .put(KEY, imageFile)
                .put(KEY,STRING_LIST)
                .put(KEY,FLOAT_LIST)
		.putModel(KEY, new Gson().fromJson(loadJSONFromAsset(context, "users.json"), User.class));
                ...
                ...
                .apply(); //.commit();
Get total data
System.out.println(sharedChamber.getPrefsSize());
Get all sharedpreferences data
Map<String,String> getAll = sharedChamber.getEverythingInChamberInMap();
Get all sharedpreferences data in List String
List<String> getAll = sharedChamber.getEverythingInChamberInList();
Get all encrypted Files inside created folder
List<CryptoFile> getFiles = sharedChamber.getAllChamberFiles();
Fetching data
sharedChamber.getString(KEY);
sharedChamber.getString(KEY,DEFAULT_VALUE);
sharedChamber.getInt(KEY);
sharedChamber.getInt(KEY,DEFAULT_VALUE);
sharedChamber.getDouble(KEY);
sharedChamber.getDouble(KEY,DEFAULT_VALUE);

//using gson
sharedChamber.getModel(KEY, User.class).toString();
sharedChamber.getModel(KEY, new TypeToken<ArrayList<Task>>(){}.getType()).toString();
.....

Bitmap bitmap = sharedChamber.getImage(KEY);   //return String path
File enc_file = sharedChamber.getFile(KEY,true);    //return File
// this getImage and getFile will totally decrypted selected file/image. You need to encrypt it back.
// just call sharedChamber.putImage(KEY,bitmap); or sharedChamber.putFile(KEY,enc_file,true);
........
Clear key and SharedPreferences
sharedChamber.destroyChamber(); //clear key
sharedChamber.clearChamber(); // clear all

sharedChamber.remove(KEY1,KEY2,KEY3,KEY4) //String... keys
sharedChamber.removeFile(KEY); //delete assosiate file (images and files) return boolean
Check if key exists
sharedChamber.contains(KEY); // return boolean
Get SharedPreferences
sharedChamber.getChamber();
Listener Data Changes
public class BaseActivity extends AppCompatActivity implements OnDataChamberChangeListener{
    ....
    @Override
    public void onDataChange(String key,String value) {
         //code here
    }
}
Easier Save User Detail Preferences
new SharedChamber.UserChamber()
.setFirstName("Firstname")
.setLastName("Lasname")
.setEmail("[email protected]")
.....
.apply(); // need to apply() or commit()

or

SharedChamber.UserChamber().applyFirstName("Firstname"); //directly apply
SharedChamber.UserChamber().applyLastName("Firstname"); //directly apply
Get User Detail
new SharedChamber.UserChamber().getFirstName()
new SharedChamber.UserChamber().getLastName()
new SharedChamber.UserChamber().getEmail()
.....
Key prefix - Apply key with prefix
new SharedChamber.UserChamber("KEY PREFIX").setFirstName("Firstname").apply();
new SharedChamber.UserChamber("KEY PREFIX").setLastName("Firstname").apply();

Extra Usage for Conceal Encryption and Decryption

SecretChamber secretChamber = new SecretBuilder(this)
                .setEnableValueEncryption(true) //default true
                .setEnableKeyEncryption(true) // default true
                .setChamberType(ChamberType.KEY_256) // ChamberType.KEY_256 or ChamberType.KEY_128
                .setPassword("Mac OSX")
                .buildSecret();
Hash
secretChamber.vaultHash(plaintext); // SHA-256
Encrypt
secretChamber.lockVault(test); // encrypt using facebook conceal
secretChamber.lockVaultBase(test,4); // encrypt using basic base64 with iteration
secretChamber.lockVaultAes("Hello World is World Hello Aes Cryption"); // encrypt using AES

//1-parameter is original location of file..it will move to other location set as in initialization
secretChamber.lockVaultFile(File file,boolean deleteOldFile);

Decrypt
secretChamber.openVault(cipher); // decrypt using facebook conceal
secretChamber.openVaultBase(cipher,4); // decrypt using basic base64 with iteration
secretChamber.openVaultAes(cipher); // decrypt using AES

secretChamber.openVaultFile(File file,boolean deleteOldFile);

Proguard

-keep class com.facebook.crypto.** { *; }
-keep class com.facebook.jni.** { *; }
-keepclassmembers class com.facebook.cipher.jni.** { *; }
-dontwarn com.facebook.**

TODO

  1. Set Preferences for specific user
  2. Able to switch Preferences between user

Credit

Facebook Conceal - Conceal provides easy Android APIs for performing fast encryption and authentication of data.
Documentation - Here

Licence

open source project that is licensed under the MIT license. Please refer to the license file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].