I'm trying to initialise retrieve my app's EncryptedSharedPreferences. I am finding that on one device (A Samsung Galaxy A52 running Android 11) the app crashes on launch due to an InvalidProtocolBufferException, with the call to EncryptedSharedPreferences.create() in the stacktrace. I cannot reproduce this on other devices, including a Samsung Galaxy A52 running Android 12.
private var encryptedPrefs = EncryptedSharedPreferences.create(
"keystoreFileName",
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
this, // "this" is my main activity
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
Here is the exception:
com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
There is also an earlier exception for the same function call, but logged as a warning.
android.security.KeyStoreException: Signature/MAC verification failed
What might cause this, and how should it be fixed?