void Save(UserConfig user) { var bytes = BytesCrypto.Encrypt(_password, JsonConvert.SerializeObject(user)); var userFolder = Scrambler.Obfuscate(user.Username, _password); var dirPath = "../sndc"; var filePath = $"{dirPath}/{userFolder}".ToLowerInvariant(); File.WriteAllBytes(filePath, bytes); }
public bool DeleteUser() { var userFolder = Scrambler.Obfuscate(_username, _password); var dirPath = "../sndc"; var filePath = $"{dirPath}/{userFolder}".ToLowerInvariant(); if (!File.Exists(filePath)) { return(false); } File.Delete(filePath); return(true); }
public UserConfig CreateOrDecrypUserConfig() { var userFolder = Scrambler.Obfuscate(_username, _password); var dirPath = "../sndc"; var filePath = $"{dirPath}/{userFolder}".ToLowerInvariant(); if (!File.Exists(filePath)) { var config = CreateUserConfig(); var bytes = BytesCrypto.Encrypt(_password, JsonConvert.SerializeObject(config)); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } File.WriteAllBytes(filePath, bytes); return(config); } var data = File.ReadAllBytes(filePath); var json = BytesCrypto.Decrypt(_password, data); return(JsonConvert.DeserializeObject <UserConfig>(json)); }