void backupKeysToServer() { // Creates key and encrypts w/ password PasswordBasedKeyHelper passHelper = new PasswordBasedKeyHelper("restoration" + mainUser.user_id); passHelper.CreateKey(suppliedRestorePassword, mainUser.email); suppliedRestorePassword = ""; // Creates dict of chatname:symkey Dictionary <string, string> keysBackup = new Dictionary <string, string>(); var chatKeyValue = myChats.Keys.ToArray <string>(); for (int i = 0; i < chatKeyValue.Length; i++) { if (!myChats[chatKeyValue[i]].hasKey()) { continue; } keysBackup[chatKeyValue[i]] = myChats[chatKeyValue[i]].getSharableKey(); } // Serializes the keys and encrypts them var serializedKeyPairs = JsonConvert.SerializeObject(keysBackup); var encryptedSerializedKeyPairs = passHelper.EncryptDataToString(serializedKeyPairs); string message = "{\"access_id\": \"" + this.access_id + "\", \"username\": \"" + mainUser.username + "\", \"backupData\": \"" + encryptedSerializedKeyPairs + "\"}"; serverConnection.WriteMessage("backupKeys", message); }