예제 #1
0
        public void StoreData()
        {
            string s = JsonConvert.SerializeObject(this.Data, Formatting.None, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            }).Trim();

            s = Sec.encrypt(s, DataSupervisor.ds.userPasswrd);
            File.WriteAllText(this.WorkingFile, s);
        }
예제 #2
0
        public void StoreData()
        {
            string saveData = JsonConvert.SerializeObject(this.Data, Formatting.Indented, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto,
            });
            string encrypted = Sec.encrypt(saveData, DataSupervisor.ds.userPasswrd);

            File.WriteAllText(this.WorkingFile, encrypted);
        }
예제 #3
0
        public void SaveUserProfile()
        {
            String userDirectory = Environment.CurrentDirectory + $"\\Data\\{this.user.userName}";

            if (!Directory.Exists(userDirectory))
            {
                Directory.CreateDirectory(userDirectory);
            }
            String rawJSON       = JsonConvert.SerializeObject(this.user);
            String encryptedJSON = Sec.encrypt(rawJSON, DataSupervisor.ds.userPasswrd);

            File.WriteAllText(userDirectory + "\\userProfile.json", encryptedJSON);
        }
예제 #4
0
 private static String IP = "127.0.0.1"; //"192.168.43.162"; // IP ADDRESS OR DOMAIN NAME
 private static bool alive()
 {
     try
     {
         byte[] data = Encoding.ASCII.GetBytes(Sec.encrypt("PING", Sec.dh_secret));
         stream.Write(data, 0, data.Length);
         w.Flush();
         if (Sec.decrypt(r.ReadLine(), Sec.dh_secret) == "PONG")
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #5
0
 private static void main()
 {
     while (true)
     {
         try
         {
             c = new TcpClient(IP, 1337);
             Thread.Sleep(2000);
             setConnected(c.Connected);
             setStream(c.GetStream());
             setReader(new StreamReader(stream));
             setWriter(new StreamWriter(stream));
             Sec.dh(stream, r, w); // diffie hellman
             while (true)
             {
                 if (!alive() || disconnect_requested)
                 {
                     disconnect_requested = false;
                     throw new SocketException();
                 }
                 if (IsPendingData())
                 {
                     String enc = Sec.encrypt(getPendingData(), Sec.dh_secret);
                     //MessageBox.Show(enc);
                     byte[] data = Encoding.ASCII.GetBytes(enc);
                     stream.Write(data, 0, data.Length);
                     w.Flush();
                     if (Sec.decrypt(r.ReadLine(), Sec.dh_secret) == "ACK")
                     {
                         // MessageBox.Show("ACK"); message recu :D
                         clearPendingData();
                     }
                     else
                     {
                         // MessageBox.Show("NAK"); message non recu, reessayer l'envoi
                     }
                 }
                 Thread.Sleep(2000);
             }
         }
         catch (SocketException)
         {
             connected = false;
             if (r != null)
             {
                 r.Dispose();
             }
             if (w != null)
             {
                 w.Dispose();
             }
             if (stream != null)
             {
                 stream.Dispose();
             }
             if (c != null)
             {
                 c.Dispose();
             }
             //MessageBox.Show("disconnected : " + e.Message);
         }
     }
 }