Using EncryptedSharedPreferences gives error Protocol message contained an invalid tag (zero)

3.7k Views Asked by At

When executing this code on a real device

String masterKeyAlias = masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
SharedPreferences settings = EncryptedSharedPreferences.create(
                    "encrypted_preferences",
                    masterKeyAlias,
                    myAppContext,
                    EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                    EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
            );

I get the following exception:

com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).

MasterKeyAlias has the value "androidx_security_master_key".

Is it some of the parameter values causing the problem or something else?android

0

There are 0 best solutions below