Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any reliable way to encrypt Shared preference in Android (Min Api 19)

I found a similar question here and lots of other articles about securing shared preferences but they all come with a warning that-

The certificate you use as the password or “secret” in your code is deleted if the lock screen method or PIN/Pattern is changed.

This is the library people suggesting to use but it has a lot of unresolved issues like if updating to Android Q they are not able to access data.

And EncryptedSharedPreferences can only be used if Min API is 23 (6.0+).

Can someone please suggest if they've found any reliable way to implement encrypt shared preferences?

like image 924
Ankit Avatar asked Nov 26 '22 13:11

Ankit


1 Answers

A new version of EncryptedSharedPreferences (https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.html) has been released, supporting API Level 21+! So if you're using version 1.1.0-alpha01 and higher, you can have minSdk version 21.

So this is what you have to put to your build.gradle(app): androidx.security:security-crypto:1.1.0-alpha01.

Time of typing this, there are newer versions, you can find out more about it here https://developer.android.com/jetpack/androidx/releases/security?authuser=1.

like image 73
Jakub Kostka Avatar answered Dec 15 '22 21:12

Jakub Kostka