static Task <string> PlatformGetAsync(string key) { var context = Platform.AppContext; string encStr = default; var foundLegacyValue = false; if (LegacyKeyHashFallback) { // If not found, could have been previously stored with md5 key if (!Preferences.ContainsKey(key, Alias)) { // If previously stored with md5 key, save with new key var md5Key = Md5Hash(key); if (Preferences.ContainsKey(md5Key, Alias)) { encStr = Preferences.Get(md5Key, null, Alias); Preferences.Set(key, encStr, Alias); foundLegacyValue = true; try { Preferences.Remove(md5Key, Alias); } catch { } } } } if (!foundLegacyValue) { encStr = Preferences.Get(key, null, Alias); } string decryptedData = null; if (!string.IsNullOrEmpty(encStr)) { try { var encData = Convert.FromBase64String(encStr); lock (locker) { var ks = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage); decryptedData = ks.Decrypt(encData); } } catch (AEADBadTagException) { System.Diagnostics.Debug.WriteLine($"Unable to decrypt key, {key}, which is likely due to an app uninstall. Removing old key and returning null."); Remove(key); } } return(Task.FromResult(decryptedData)); }
static bool PlatformRemove(string key) { var context = Platform.AppContext; key = Utils.Md5Hash(key); Preferences.Remove(key, Alias); return(false); }
static bool PlatformRemove(string key) { var context = Platform.AppContext; Preferences.Remove(key, Alias); CheckForAndRemoveLegacyKey(key); return(true); }
static bool PlatformRemove(string key) { var keyHash = Md5Hash(key); if (Preferences.ContainsKey(keyHash, Alias)) { Preferences.Remove(keyHash, Alias); return(true); } return(false); }
static void CheckForAndRemoveLegacyKey(string key) { if (LegacyKeyHashFallback) { var md5Key = Md5Hash(key); if (Preferences.ContainsKey(md5Key, Alias)) { try { Preferences.Remove(md5Key, Alias); } catch { } } } }