public async Task Fix_Corrupt_Data(string key, string data) { // this operation is only available on API level 23+ devices if (!OperatingSystem.IsAndroidVersionAtLeast(23)) { return; } // set a valid key await SecureStorage.SetAsync(key, data); // simulate corrupt the key var corruptData = "A2PfJSNdEDjM+422tpu7FqFcVQQbO3ti/DvnDnIqrq9CFwaBi6NdXYcicjvMW6nF7X/Clpto5xerM41U1H4qtWJDO0Ijc5QNTHGZl9tDSbXJ6yDCDDnEDryj2uTa8DiHoNcNX68QtcV3at4kkJKXXAwZXSC88a73/xDdh1u5gUdCeXJzVc5vOY6QpAGUH0bjR5NHrqEQNNGDdquFGN9n2ZJPsEK6C9fx0QwCIL+uldpAYSWrpmUIr+/0X7Y0mJpN84ldygEVxHLBuVrzB4Bbu5XGLUN/0Sr2plWcKm7XhM6wp3JRW6Eae2ozys42p1YLeM0HXWrhTqP6FRPkS6mOtw=="; var all = PreferencesImplementation.GetSharedPreferences(SecureStorageImplementation.Alias).All; Preferences.Set(all.Keys.First(x => !x.StartsWith("_")), corruptData, SecureStorageImplementation.Alias); var c = await SecureStorage.GetAsync(key); Assert.Null(c); // try to reset and get again await SecureStorage.SetAsync(key, data); c = await SecureStorage.GetAsync(key); Assert.Equal(data, c); }
static void PlatformRemoveAll() { lock (locker) { using (var editor = PreferencesImplementation.GetSharedPreferences(Alias).Edit()) { editor.Clear().Apply(); } } }