All Projects → adorsys → Secure Storage Android

adorsys / Secure Storage Android

Licence: apache-2.0
Store strings & credentials securely encrypted on your device

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Secure Storage Android

Itext7 Dotnet
iText 7 for .NET is the .NET version of the iText 7 library, formerly known as iTextSharp, which it replaces. iText 7 represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText 7 can be a boon to nearly every workflow.
Stars: ✭ 698 (+109.61%)
Mutual labels:  library, encryption
Kissme
Kissme: Kotlin Secure Storage Multiplatform
Stars: ✭ 351 (+5.41%)
Mutual labels:  library, encryption
Libzip
A C library for reading, creating, and modifying zip archives.
Stars: ✭ 379 (+13.81%)
Mutual labels:  library, encryption
Itext7
iText 7 for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText 7 can be a boon to nearly every workflow.
Stars: ✭ 913 (+174.17%)
Mutual labels:  library, encryption
Py7zr
7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.
Stars: ✭ 110 (-66.97%)
Mutual labels:  library, encryption
Ksprefs
🚀⚡ Kotlin SharedPreferences wrapper & cryptographic preferences android library.
Stars: ✭ 176 (-47.15%)
Mutual labels:  library, encryption
Bt
BitTorrent library and client with DHT, magnet links, encryption and more
Stars: ✭ 2,011 (+503.9%)
Mutual labels:  library, encryption
Pgsodium
Modern cryptography for PostgreSQL using libsodium.
Stars: ✭ 202 (-39.34%)
Mutual labels:  library, encryption
Tensorflow Windows Wheel
Tensorflow prebuilt binary for Windows
Stars: ✭ 3,428 (+929.43%)
Mutual labels:  library
Clojure.java Time
Java 8 Date-Time API for Clojure
Stars: ✭ 323 (-3%)
Mutual labels:  library
React Component Library
A project skeleton to get your very own React Component Library up and running using Rollup, Typescript, SASS + Storybook
Stars: ✭ 313 (-6.01%)
Mutual labels:  library
File
The Hoa\File library.
Stars: ✭ 322 (-3.3%)
Mutual labels:  library
Unstated Next
200 bytes to never think about React state management libraries ever again
Stars: ✭ 3,784 (+1036.34%)
Mutual labels:  library
Tintlayout
This library help you to achieve popular drop shadow effect from view.
Stars: ✭ 322 (-3.3%)
Mutual labels:  library
Crashreporter
CrashReporter is a handy tool to capture app crashes and save them in a file.
Stars: ✭ 327 (-1.8%)
Mutual labels:  library
Jackrabbit Oak
Mirror of Apache Jackrabbit Oak
Stars: ✭ 321 (-3.6%)
Mutual labels:  library
Event
The Hoa\Event library
Stars: ✭ 319 (-4.2%)
Mutual labels:  library
Metrics Clojure
A thin façade around Coda Hale's metrics library.
Stars: ✭ 330 (-0.9%)
Mutual labels:  library
Easyvalidation
✔️ A text and input validation library in Kotlin for Android
Stars: ✭ 328 (-1.5%)
Mutual labels:  library
Hoplite
A boilerplate-free library for loading configuration files as data classes in Kotlin
Stars: ✭ 322 (-3.3%)
Mutual labels:  library

Secure Device Storage - Android

Storing Credentials Securely on Android Devices

Actions Status Download Android Arsenal API License Open Source Love

Introduction

Storing credentials securely on a device is in many occasions necessary. You probably don't want to rely only on the separation of processes of the Android OS but make sure the stored values are also encrypted. To make that possible we have combined the Android Keystore and the SharedPreferences. The keystore is used for generating cryptographic keys, the values are then encrypted with these keys and subsequently securely stored in the SharedPreferences.

The secure part about this solution is that those generated keys are never exposed to the kernel when the device is equipped with a “Trusted Execution Environment”. A so called TEE is a secure area inside the main processor of a smartphone which runs code isolated from other processes. That means even if the device gets compromised or hacked those keys can’t be extracted. Already a lot of modern Android phones out there are equipped with a TEE (mostly because it’s often used to play DRM protected material) and it even is a requirement for Google’s Android Nougat certification — so every phone running Android Nougat and later will come with a TEE installed.

SecureStorage uses its own dedicated private SharedPreferences to prevent conflicts with other possible SharedPreference instances and ensure that the content of the SecureStorage can only be accessed from the app which uses this library.

Supported API's

Symmetric key generation and storage in the Android KeyStore is supported from Android 6.0 (API Level 23) onwards. Asymmetric key generation and storage in the Android KeyStore is supported from Android 4.3 (API Level 18) onwards.

To support more devices SecureStorage uses for now the asymmetric key generation, which in the case of storing simple credentials is very secure and the potential lack of speed in contrast to symmetric key generation, is not noticeable. Nevertheless, make sure to move the execution into a background thread as encryption does take a little time.

Usage

Add the library to your apps build.gradle:

implementation "de.adorsys.android:securestoragelibrary:${latestSecureStorageVersion}"

To store a string value in your SecureStorage you have to call:

SecurePreferences.setValue(context, "KEY", "PLAIN_MESSAGE")

This works for every other primitive data type. So for storing a boolean value:

SecurePreferences.setValue(context, "KEY", true/false)

for int

SecurePreferences.setValue(context, "KEY", 100)

for float and long

SecurePreferences.setValue(context, "KEY", 100.12345)

To retrieve a string value:

SecurePreferences.getStringValue(context, "KEY", ""/null)

And respectively for the other types

SecurePreferences.getBooleanValue(context, "KEY", false/true)
SecurePreferences.getIntValue(context, "KEY", 0)
SecurePreferences.getFloatValue(context, "KEY", 0F)
SecurePreferences.getLongValue(context, "KEY", 0L)

See if an entry exists in the SecurePreferences. Also returns false if the key pair does not exist:

SecurePreferences.contains(context, "KEY")

You can also remove an entry from the SecurePreferences:

SecurePreferences.removeValue(context, "KEY")

Clearing the SecurePreferences and deleting the KeyPair:

SecurePreferences.clearAllValues(context)

Everything about the cryptographic keys such as generating, maintaining and usage is handled internally by the module, so you do not need to worry about it.

If you want to keep track of changes in your SecureStorage you can register an OnSharedPreferencesChangeListener as follows:

val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
    // check if the key is the one you are listening for and react
}
SecurePreferences.registerOnSharedPreferenceChangeListener(this, listener)

Unregister the listener as soon as you don't need it any more with

SecurePreferences.unregisterOnSharedPreferenceChangeListener(context, listener)

Error handling

The library throws for everything a SecureStorageException. Within the SecureStorageException you can find a exception type. You can handle the error which occurred with the help of this type as follows:

try {
    SecurePreferences.setValue(context, KEY, "Secret")
    // or
    val decryptedMessage = SecurePreferences.getStringValue(context, KEY, "")
} catch (e: SecureStorageException) {
    handleException(e)
}
//
private fun handleException(e: SecureStorageException) {
    Log.e(TAG, e.message)
    when (e.type) {
        KEYSTORE_NOT_SUPPORTED_EXCEPTION -> Toast.makeText(this, "Oh", Toast.LENGTH_LONG).show()
        KEYSTORE_EXCEPTION -> Toast.makeText(this, "Fatal - YARK", Toast.LENGTH_LONG).show()
        CRYPTO_EXCEPTION -> Toast.makeText(this, "2h&$==0j", Toast.LENGTH_LONG).show()
        INTERNAL_LIBRARY_EXCEPTION -> Toast.makeText(this, "Blame it all on us", Toast.LENGTH_LONG).show()
        else -> return
    }
}

Contributors:

@drilonrecica

@luckyhandler

Want to know more:

These links cover security aspect of the android keystore: https://developer.android.com/training/articles/keystore.html#SecurityFeatures https://source.android.com/security/keystore/ https://codingquestion.blogspot.de/2016/09/how-to-use-android-keystore-api-with.html http://nelenkov.blogspot.de/2012/05/storing-application-secrets-in-androids.html http://nelenkov.blogspot.de/2015/06/keystore-redesign-in-android-m.html http://www.androidauthority.com/use-android-keystore-store-passwords-sensitive-information-623779/

This link covers security aspect of the android storage: https://developer.android.com/guide/topics/data/data-storage.html http://stackoverflow.com/a/26077852/3392276

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].