public async Task <User> Login(string login, string password) { var properties = _propertyHandler.Load(); if (login != properties.Login) { throw new ArgumentException("Zły login"); } if (password != properties.Password) { throw new ArgumentException("Złe hasło"); } var request = new UserRequest() { Login = login, Password = password }; var jwt = await HttpClientWrapper.PostAsync <Jwt>(ApiEndpoints.Login, request); HttpClientWrapper.Authenticate(jwt.Token); var user = jwt.User; user.Token = jwt.Token; if (user == null) { throw new Exception("Nie znaleziono użytkownika w bazie."); } user.Password = properties.Password; user.PublicKey = properties.PublickKey; user.PrivateKey = properties.PrivateKey; var newContacts = await HttpClientWrapper.GetAsync <List <NewContact> >(ApiEndpoints.NewContacts); if (newContacts != null) { foreach (var newContact in newContacts) { var key = _cryptographyProvider.RSA.Decrypt(newContact.SymmetricKey, user.PrivateKey); var iv = _cryptographyProvider.RSA.Decrypt(newContact.IV, user.PrivateKey); properties.Keys.Add(newContact.ContactName, new AesKey(key, iv)); } _propertyHandler.Save(properties); } _userSettings.User = user; _userSettings.Keys = properties.Keys; return(user); }