All Projects → Ufkoku → CipherSharedPrefs

Ufkoku / CipherSharedPrefs

Licence: Apache-2.0 license
Library implements encrypion layer for SharedPreferences. Also adds some additional features

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to CipherSharedPrefs

Appdatareader
A library for reading Shared Preferences and Database values within the application.
Stars: ✭ 126 (+740%)
Mutual labels:  sharedpreferences
Frideos flutter
An all-in-one Fllutter package for state management, reactive objects, animations, effects, timed widgets etc.
Stars: ✭ 187 (+1146.67%)
Mutual labels:  sharedpreferences
Aptpreferences
基于apt实现的Android快速持久化框架:AptPreferences
Stars: ✭ 227 (+1413.33%)
Mutual labels:  sharedpreferences
Bulldog
Android library to simplify reading and writing to SharedPreferences, never write code like this anymore prefs.edit().putString("someKey","someString").apply()
Stars: ✭ 133 (+786.67%)
Mutual labels:  sharedpreferences
Oksharedprefs
通过注解生成SharedPreferences包装类,解决跨进程数据访问不同步的问题。
Stars: ✭ 183 (+1120%)
Mutual labels:  sharedpreferences
Tray
a SharedPreferences replacement for Android with multiprocess support
Stars: ✭ 2,314 (+15326.67%)
Mutual labels:  sharedpreferences
Secure Preferences
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.
Stars: ✭ 1,527 (+10080%)
Mutual labels:  sharedpreferences
Awesome-Android-Persistence
A curated list of awesome android persistence libraries about SQLite, ORM, Mobile Database, SharedPreferences, etc.
Stars: ✭ 69 (+360%)
Mutual labels:  sharedpreferences
Android Prefs
Android preferences for WINNERS!
Stars: ✭ 183 (+1120%)
Mutual labels:  sharedpreferences
Armadillo
A shared preference implementation for confidential data in Android. Per default uses AES-GCM, BCrypt and HKDF as cryptographic primitives. Uses the concept of device fingerprinting combined with optional user provided passwords and strong password hashes.
Stars: ✭ 226 (+1406.67%)
Mutual labels:  sharedpreferences
React Native Default Preference
Use SharedPreference (Android) and UserDefaults (iOS) with React Native over a unified interface
Stars: ✭ 170 (+1033.33%)
Mutual labels:  sharedpreferences
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (+1113.33%)
Mutual labels:  sharedpreferences
Redux Persist Sensitive Storage
redux-persist storage engine for react-native-sensitive-info
Stars: ✭ 209 (+1293.33%)
Mutual labels:  sharedpreferences
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (+780%)
Mutual labels:  sharedpreferences
Prefser
Wrapper for Android SharedPreferences with object serialization and RxJava Observables
Stars: ✭ 228 (+1420%)
Mutual labels:  sharedpreferences
Prefs
Simple Android SharedPreferences wrapper.
Stars: ✭ 125 (+733.33%)
Mutual labels:  sharedpreferences
Typedpreferences
Preference wrappers for primitive types for Android
Stars: ✭ 191 (+1173.33%)
Mutual labels:  sharedpreferences
Android-SharedPreferences-Helper
This Shared Preferences Helper library (Library size = ~15kb only) Simplifies usage of the default Android SharedPreferences Class. The developer can do in a few lines of code which otherwise would have required several. Simple to understand as compared to the default Shared Preferences class and easy to use. Can be used by simply adding the dep…
Stars: ✭ 15 (+0%)
Mutual labels:  sharedpreferences
Serialize
🍒 Android 简单高性能读写本地数据, 直接存储对象/基础类型
Stars: ✭ 181 (+1106.67%)
Mutual labels:  sharedpreferences
Krate
A SharedPreferences wrapper powered by Kotlin delegates
Stars: ✭ 213 (+1320%)
Mutual labels:  sharedpreferences

@Deprecated Use androidx.EncryptedSharedPreferences instead

CipherSharedPrefs

alt tag

CipherSharedPrefs implements SharedPreferences with encryption layer and some new features.

repositories {
    maven { url 'https://dl.bintray.com/ufkoku/maven/' }
}

dependencies {
    compile 'com.ufkoku.cipher_sharedprefs:sharedprefs:version'
    //or
    compile 'com.ufkoku.cipher_sharedprefs:sharedprefs:version@aar'{
        transitive = true
    }
}

How it works

When you put value to CipherSharedPreferences it is transformed to String and encrypted by provided ICipherHolder object, encryped string is saved to SharedPreferences delegate.

new CipherSharedPreferences(
                context.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE),
                iCipherHolder,
                iCacheHolder, //optional
                iTransformer //optional
        )

Cipher

You must provide implementation of ICipherHolder to CipherSharedPreferences constructor. It is used for data encryption and decryption.

Library contains AES implementation AesCipher.

  • Default mode: ECB;
  • Supported modes: CBC, CFB, CTR, ECB, OFB;
  • IV requires modes: CBC, CFB, OFB, CTR;
  • Supported keys: Supported size 128/192/256 bits -> 16/24/32 bytes;
  • IV lenght: equals to key lenght;

IV - initialization vector

dependencies {
    compile 'com.ufkoku.cipher_sharedprefs:ciphers:version'
    //or
    compile 'com.ufkoku.cipher_sharedprefs:ciphers:version@aar'{
        transitive = true
    }
}

Cache (Optional)

You can provide ICacheHolder to CipherSharedPreferences.

If ICacheHolder exists, values WITHOUT encryption will be saved there, after get/put methods for key.
When you call get methods, CipherSharedPreferences checks cache, and if value exists - it will be returned, otherwise it will be decrypted from delegate, and saved to cache.
When you call put methods, CipherSharedPreferences saves value to cache WITHOUT encryption, and encrypted string to delegate.

PROS

  • When you getting value, that contains in cache, you are not spending time on decryption.

LIMITATIONS

  • If you use cache, you should use CipherSharedPreferences or ICacheHolder as singleton, cache won't be refreshed if you modify prefs from another instance.

There are already implemented cache holders, that you can use in module caches

dependencies {
    compile 'com.ufkoku.cipher_sharedprefs:caches:version'
    //or
    compile 'com.ufkoku.cipher_sharedprefs:caches:version@aar'{
        transitive = true
    }
}

Implementations:

  • SharedPrefsLruCache wrap over SizeBasedEnhancedLruCache, it limits cache by size in bytes.
  • SharedPrefsMapCache wrap over HashMap

Object saving (Optional)

CipherSharedPreferences can save objects and retrieve them back via methods

CipherSharedPreferences {
    
    //get object
    <T> getObject(key: String, defValue: T?, clazz: Class<T>): T?

    CipherEditor{
        //save object
        putObject(key: String, value: Any?): SharedPreferences.Editor
    }

}

To use this feature you need to provide ITransformer implementation to CipherSharedPreferences constructor.

//Example of ITransformer
//This transformer uses GSON to transform input objects to string and back.
transformer = new ITransformer() {
            private Gson gson = new Gson();

            @NotNull
            @Override
            public String toString(@NotNull Object o) {
                return gson.toJson(o);
            }

            @Override
            public <T> T fromString(@NotNull String string, @NonNull Class<T> clazz) {
                return gson.fromJson(string, clazz);
            }
            
        };

Example of usage

        Set<String> value = new HashSet<>();
        value.add("str1");
        value.add("str2");
        value.add("str3");
        
        preferences.edit().putObject(KEY_1, value).commit();
        preferences.getObject(KEY_1, null, value.getClass())        
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].