【问题标题】:Minimum API level for using android EncryptedSharedPreference?使用 android EncryptedSharedPreference 的最低 API 级别?
【发布时间】:2020-06-18 20:43:43
【问题描述】:

android encryptedShared 首选项所需的最低 API 级别是多少?

我正在使用以下依赖项

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

我的最低 API 级别是 21,我读过共享偏好所需的最低 API 是 23。

如果我可以在我的代码中放置类似 API 23 之类的逻辑,请使用常规 sharedPreference(我使用服务器来存储关键数据)并且我永远不会初始化加密共享首选项,并且在 API23+ 中我使用加密共享首选项。

我的代码在低于 API23 的情况下编译和运行会不会出现任何问题?

【问题讨论】:

标签: android encryption


【解决方案1】:

我的代码在低于 API23 的情况下编译和运行会不会出现任何问题?

是的

用于通过 API 级别检查创建 SharedPreferencesEncryptedSharedPreferences

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)
    }
  }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多