Exemple #1
0
        public List <IdLoginClient> GetAllClients(int id)
        {
            List <IdLoginClient> res = new List <IdLoginClient>();

            UsersContext usersContext = new UsersContext();
            //string strId = Convert.ToString(id.Id);
            var buffer = usersContext.users.Select(i => new { Id = i.Id, Login = i.Login }).ToList();

            foreach (var v in buffer)
            {
                res.Add(new IdLoginClient()
                {
                    Id = Convert.ToString(v.Id), Login = v.Login
                });
            }

            //Encrypt the users data
            Session     sender       = FindSessionByClientId(id);
            string      actualKey    = ExtensionClass.ByteArrayToString(sender.ServerKey);
            string      subActualKey = actualKey.Substring(0, 8);
            IdeaChipher idea         = new IdeaChipher(subActualKey);

            for (int i = 0; i < res.Count; i++)
            {
                res[i].Id    = idea.Encrypt(res[i].Id);
                res[i].Login = idea.Encrypt(res[i].Login);
            }

            return(res);
        }
Exemple #2
0
        public int GetCountAndNamesOfFiles(out string projectName, out string[] fileNames, int senderId, int forId)
        {
            int count;

            string pathString = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            pathString = System.IO.Path.Combine(pathString, forId + "-" + senderId);
            string[] directories  = Directory.GetDirectories(pathString);
            string   projectName_ = directories[0];

            string[] fileNames_ = Directory.GetFiles(projectName_);

            Session     sender       = FindSessionByClientId(forId);
            string      actualKey    = ExtensionClass.ByteArrayToString(sender.ServerKey);
            string      subActualKey = actualKey.Substring(0, 8);
            IdeaChipher idea         = new IdeaChipher(subActualKey);

            count       = fileNames_.Length;
            projectName = idea.Encrypt(projectName_);
            fileNames   = new string[fileNames_.Length];

            for (int i = 0; i < fileNames_.Length; i++)
            {
                fileNames[i] = idea.Encrypt(fileNames_[i]);
            }

            return(count);
        }
Exemple #3
0
        //public MainWindow ServiceWindow
        //{
        //    get; set;
        //}

        public bool SendToServer(string encryptedMessage, int idFrom, string fileName, string containerName)
        {
            bool res = false;



            try
            {
                Session sender = FindSessionByClientId(idFrom);
                int     idTo;

                string      actualKey    = ExtensionClass.ByteArrayToString(sender.ServerKey);
                string      subActualKey = actualKey.Substring(0, 8);
                IdeaChipher idea         = new IdeaChipher(subActualKey);


                //string encryptedMessageOld = encryptedMessage;

                if (idea.SurrogatePairsDetected(encryptedMessage))
                {
                    encryptedMessage = idea.DeleteAdditionalPartsFromSurrogetePairs(encryptedMessage);
                }

                string idRecipientStr = encryptedMessage.Substring(encryptedMessage.Length - 4, 4);
                encryptedMessage = encryptedMessage.Substring(0, encryptedMessage.Length - 4);
                idRecipientStr   = idea.Decrypt(idRecipientStr);

                idTo = Convert.ToInt32(idRecipientStr);
                string buffer = idea.Decrypt(encryptedMessage);

                WriteToFile(buffer, fileName, containerName, idFrom, idTo);
                //WriteToFile(encryptedMessageOld, fileName + ".enc", containerName, idFrom, idTo);
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
                throw ex;
            }

            return(res);
        }
Exemple #4
0
        public string SignIn(string login, string password)
        {
            string res = string.Empty;

            if (login.Equals(string.Empty) || password.Equals(string.Empty))
            {
                throw new ArgumentException("SignIn method. Empty parameters!");
            }
            Session sender = FindSessionByClientId(defaultClientId);

            string      actualKey    = ExtensionClass.ByteArrayToString(sender.ServerKey);
            string      subActualKey = actualKey.Substring(0, 8);
            IdeaChipher idea         = new IdeaChipher(subActualKey);

            if (idea.SurrogatePairsDetected(login))
            {
                login = idea.DeleteAdditionalPartsFromSurrogetePairs(login);
            }

            if (idea.SurrogatePairsDetected(password))
            {
                password = idea.DeleteAdditionalPartsFromSurrogetePairs(password);
            }

            login    = idea.Decrypt(login);
            password = idea.Decrypt(password);
            //should be changed to custom deleting the spaces only at the right side
            login    = login.Trim();
            password = password.Trim();

            int id = GetIdAndVerifyPas(login, password);

            res = id.ToString();
            res = idea.Encrypt(res);

            //ServiceWindow.LogTextBlock.Text += string.Format("Sign in id: {0} ", res);

            return(res);
        }
Exemple #5
0
        public string[] GetContents(string[] encryptedNames, int idFor)
        {
            string[] result = new string[encryptedNames.Length];

            Session     sender       = FindSessionByClientId(idFor);
            string      actualKey    = ExtensionClass.ByteArrayToString(sender.ServerKey);
            string      subActualKey = actualKey.Substring(0, 8);
            IdeaChipher idea         = new IdeaChipher(subActualKey);

            string[] decryptedNames = new string[encryptedNames.Length];
            for (int i = 0; i < encryptedNames.Length; i++)
            {
                decryptedNames[i] = idea.Decrypt(encryptedNames[i]);
            }

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = File.ReadAllText(decryptedNames[i]);
                result[i] = idea.Encrypt(result[i]);
            }

            return(result);
        }