Beispiel #1
0
        /*~ContactInfo()
         * {
         *  this.StoreData();
         * }*/

        public ContactInfo(string WorkingFile)
        {
            this.WorkingFile = WorkingFile;
            bool   exists   = true;
            string SaveFile = "";

            try
            {
                SaveFile = File.ReadAllText(this.WorkingFile).Trim();
            }
            catch
            {
                exists = false;
            }
            if (exists)
            {
                SaveFile  = Sec.decrypt(SaveFile, DataSupervisor.ds.userPasswrd);
                this.Data = new Dictionary <string, ContactData>();
                this.Data = JsonConvert.DeserializeObject <Dictionary <string, ContactData> >(SaveFile, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Auto
                });
            }
            else
            {
                this.Data = new Dictionary <string, ContactData>();
            }
        }
Beispiel #2
0
        public CalendarInfo(string WorkingFile, DateTime month)
        {
            this.WorkingFile = WorkingFile;
            this.Month       = month;
            bool   exists   = true;
            string SaveFile = "";

            try
            {
                SaveFile = File.ReadAllText(this.WorkingFile);
            } catch (FileNotFoundException)
            {
                exists = false;
            }
            if (exists)
            {
                SaveFile = Sec.decrypt(SaveFile, DataSupervisor.ds.userPasswrd);
            }
            else
            {
                SaveFile = "{}";
            }
            this.Data = (Dictionary <DateTime, List <CalendarObj> >)JsonConvert.DeserializeObject(SaveFile, this.Data.GetType(), new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            });
        }
Beispiel #3
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);
     }
 }
Beispiel #4
0
        // Loads the user profile data from its corresponding file
        private void LoadUserProfile(String username)
        {
            string dataPath = this.currentUserDataPath + @"\userProfile.json";

            if (this.user != null)
            {
                return;
            }
            if (File.Exists(dataPath))
            {
                String rawJSON       = "{}";
                String decryptedJSON = "{}";
                rawJSON = File.ReadAllText(dataPath).Trim();
                if (rawJSON == "")
                {
                    decryptedJSON = "{}";
                }
                else
                {
                    decryptedJSON = Sec.decrypt(rawJSON, DataSupervisor.ds.userPasswrd);
                }
                this.user = JsonConvert.DeserializeObject <User>(decryptedJSON);
            }
        }
Beispiel #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);
         }
     }
 }