/// <summary> /// Encrypts and writes a string to the NetworkStream. /// </summary> /// <param name="str">The string to encrypt and send</param> public void Write(string str) { var m = SecureMessage.FormMessage(++messageCount, str, isServer); streamWriter.WriteLine(sessionAES.Encrypt(m)); streamWriter.Flush(); }
/// <summary> /// Read and decrypts a string from the NetworkStream. /// </summary> /// <returns>The dycrypted string.</returns> public SecureMessage Read() { string encrypted = streamReader.ReadLine(); string unparsed = ""; try { unparsed = sessionAES.Decrypt(encrypted); } catch (Exception) { return(new SecureMessage("Decript Exception Thrown.")); } var sm = new SecureMessage(unparsed, othersMessageCount, isServer); if (sm.isSecure == true) { if (verbose && sm.Count - othersMessageCount > 1) { Console.WriteLine("Missing " + (sm.Count - othersMessageCount).ToString() + "Messages"); } othersMessageCount = sm.Count; } return(sm); }