简体   繁体   中英

Minimum API level for using android EncryptedSharedPreference?

What is the minimum API level required for android encryptedShared preference?

I'm using following dependency

implementation "androidx.security:security-crypto:1.0.0-alpha02"

My minimum API level is 21, I've read that minimum API required for shared preference is 23.

If in my code can I put a logic like below API 23 use regular sharedPreference(I use server to store critical data) and I will never initialize encrypted shared preference and in API23+ I use encrypt shared preference.

Will my code compile and run without any issue in below API23?

Will my code compile and run without any issue in below API23?

Yes

For creating SharedPreferences OR EncryptedSharedPreferences on with API Level check

object PrefMgr {
  private var preferences: SharedPreferences? = null

  init {
    preferences = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        EncryptedSharedPreferences.create(
            context,
            APP_PREF_FILE,
            MasterKey.Builder(context)
                .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
                .build(),
            EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
            EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
        )
    } else {
        context.getSharedPreferences(APP_PREF_FILE, Context.MODE_PRIVATE)
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM