secure-preferences


Source link: https://github.com/ophio/secure-preferences

For securing your SharedPreferences information.

Why Secure SharedPreferences?

SharedPreferences are accessible to anybody if your device is compromised. It is recommended to obscure the information saved in SharedPreferences before you store them. One of the solutions is to encrypt the informaiton (See [ ObscuredSharedPreferences] (library/src/main/java/in/co/ophio/secure/core/ObscuredSharedPreferences.java)). Still the key that is used for encryption can be recovered by a simple decompilation procedure if it is hard-coded in the app.

Solution

In addition to encrypting the information stored in SharedPreferences, store your encryption key in the [ Android Keystore System] ( https://developer.android.com/training/articles/keystore.html#UsingAndroidKeyStore) by using our KeyGenerator

Android Keystore System

The Android Keystore system lets you store private keys in a container to make it more difficult to extract from the device. Once keys are in the keystore, they can be used for cryptographic operations with the private key material remaining non-exportable.

The Keystore system is used by the KeyChain API as well as the Android Keystore provider feature that was introduced in Android 4.3 (API level 18).

Disadvantages of using Android Keystore System

If we create a key pair with the KeyPairGenerator and store it, then on changing the screen lock, our key pairs are deleted as the new Keystore is empty. See the following links for more details:

There are some changes to the Keystore in the new Android M Developer Preview regarding this mentioned here.

Download

Using Gradle:

compile "in.co.ophio:secure-preferences:0.1.3" 

Using Maven:

<dependency>
<groupId>in.co.ophio</groupId>
<artifactId>secure-preferences</artifactId>
<version>0.1.3</version> </dependency> 

Usage

 String key = KeyStoreKeyGenerator.get(getApplication(),

KeystoreApplication.getAppContext().getPackageName())

 .loadOrGenerateKeys();
 
  • Obtain an instance of [ ObscuredSharedPreferences] (library/src/main/java/in/co/ophio/secure/core/ObscuredSharedPreferences.java) using ObscuredPreferencesBuilder as follows:
SharedPreferences sharedPreferences = new ObscuredPreferencesBuilder()

  .setApplication(KeystoreApplication.getAppContext())

  .obfuscateValue(true)

  .obfuscateKey(true)

  .setSharePrefFileName(PREFS_NAME)

  .setSecret(key)  //secret key we generated in step 1.

  .createSharedPrefs();
 

Contributing

Before sending pull requests

  • Setup your Preferences -> File And Code Templates -> Includes -> File Header as follows:
/**  * @author ${
USER
}
 (your email address)  */ 
  • Run the following command on your computer.
./gradlew clean check connectedAndroidTest 

License

Copyright 2015 Ophio.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Demo for the EventBus library of GreenRobot.

Progress Image is a library for modern progress view style it's replace the normal progress carousel with image/icon as a progress view for your application plus switch between some animations.

This is a simple rxjava2 timer.

A small library which creates iPad-style ActionSheet for Android apps.

Generates public.xml for Android libraries, which allows resources to be hidden from clients. More info

A simple, minimalistic and beautiful dialog color picker for Android 4.1+ devices. This color picker is easy-to-use and easy-to-integrate in your application to let users of your app choose color in a simple way.

Features:

  • Get Hex and (A)RGB color codes
  • Set color using (A)RGB values and get HEX codes
  • Set color using HEX value
  • Separate UI for portrait and landscape devices
  • Support for pre-lollipop devices

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes