/// <summary> /// creates new DB entry for contact and reloads contacts list. To get updated list of contacts use getContacts(). /// </summary> /// <param name="name">Name of contact</param> /// <param name="IPAddress">IP address of contact</param> public void addContact(string name, string IPAddress) { //non-return query on database //db.update($"INSERT INTO Users (username, IPAddress) VALUES (\"{name}\",\"{IPAddress}\")"); //ID incremented by DBMS //loadContacts(); //reload list from DB //create list of byte arrays to be encrypted with the same initialisation vector List <byte[]> data = new List <byte[]>() { Encoding.UTF8.GetBytes(name), Encoding.UTF8.GetBytes(IPAddress) }; Tuple <IEnumerable <byte[]>, byte[]> encResult = CryptoUtility.AESEncryptCollection(data, Globals.getMasterKey()); data = (List <byte[]>)encResult.Item1; //extracts list of encrypted bytes from result byte[] encName = data[0]; byte[] encIPAddress = data[1]; byte[] IV = encResult.Item2; //initialisation vector used to encrypt both values //non-return query on database db.userInsert($"INSERT INTO Users (username, IPAddress, IV) VALUES (@username,@IPAddress,@IV)", encName, encIPAddress, IV); loadContacts(); //reload list form DB }