How to create masterKey after MasterKeys deprecated in Android

前端 未结 5 1206
南方客
南方客 2021-01-04 09:36

I am using the following code to store some information encrypted in my app.

    val masterKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)

    val s         


        
5条回答
  •  一向
    一向 (楼主)
    2021-01-04 10:09

    My version to get secret shared preference :

    private fun getSecretSharedPref(context: Context): SharedPreferences {
        val masterKey = MasterKey.Builder(context)
                .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
                .build()
    
        return EncryptedSharedPreferences.create(context,
                "secret_shared_prefs",
                masterKey,
                EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
        )
    }
    

提交回复
热议问题