static byte[] ZipEncrypt(LocalEvent e, string secretKey) { var bytes = Encoding.UTF8.GetBytes(e.Json()); var compressed = bytes.Compress(); var encrypted = BytesCrypto.EncryptFromBytes(secretKey, compressed); return(encrypted); }
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 LocalEvent GetEvent(string secretKey) { if (_event == null) { var decrypted = BytesCrypto.DecryptToBytes(secretKey, ZipEncryptedData); var decompressed = decrypted.Decompress(); var json = Encoding.UTF8.GetString(decompressed); _event = (LocalEvent)json.Parse(AssemblyQualifiedName); } return(_event); }
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)); }