private byte[] TryGetAndMigrate(string key) { if (_oldKeyStorageService.Contains(key)) { var value = _oldKeyStorageService.Retrieve(key); Store(key, value); return(value); } var formattedKeyV1 = string.Format(SettingsFormatV1, key); if (_settings.Contains(formattedKeyV1)) { var aesKeyV1 = GetAesKey(true); if (aesKeyV1 != null) { try { var cs = _settings.GetValueOrDefault(formattedKeyV1, null); var value = App.Utilities.Crypto.AesCbcDecrypt(new App.Models.CipherString(cs), aesKeyV1); Store(key, value); return(value); } catch { Console.WriteLine("Failed to decrypt v1 from secure storage."); } } _settings.Remove(formattedKeyV1); } return(null); }
public string GetTwoFactorToken(string email) { var emailEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(email)); var tokenBytes = _secureStorage.Retrieve(string.Format(TwoFactorTokenKeyFormat, emailEncoded)); if (tokenBytes == null) { return(null); } return(Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length)); }
private string GetAppId(string key, ref Guid?appId) { if (appId.HasValue) { return(appId.Value.ToString()); } var appIdBytes = _secureStorageService.Retrieve(key); if (appIdBytes != null) { appId = new Guid(appIdBytes); return(appId.Value.ToString()); } appId = Guid.NewGuid(); _secureStorageService.Store(key, appId.Value.ToByteArray()); return(appId.Value.ToString()); }