Ejemplo n.º 1
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            bool correctInput = GetSelectedValuesFromGUIRegister(out string email, out string password);

            if (correctInput)
            {
                User newUser = UsersManagement.AddUser(email, password);
                users.Add(newUser);
                RecipentsListBox.ItemsSource           = null;
                RecipentsListBoxDecryption.ItemsSource = null;
                RecipentsListViewRegister.ItemsSource  = null;


                RecipentsListBox.ItemsSource           = users;
                RecipentsListBoxDecryption.ItemsSource = users;
                RecipentsListViewRegister.ItemsSource  = users;

                resultTextBlockRegister.Text = "Zostałeś zarejestrowany, dziękujemy ! Tak na prawde nie xd";
            }
            else
            {
                resultTextBlockRegister.Text = "błąd rejestracji";

                //TODO error message about incorrect input
            }
        }
Ejemplo n.º 2
0
        private void PrepareAppUsers()
        {
            users = UsersManagement.GetUsersListFromFile();

            //set listbox to display all users (as potential recipents of encrypted data)
            RecipentsListBox.ItemsSource           = users;
            RecipentsListBoxDecryption.ItemsSource = users;
            RecipentsListViewRegister.ItemsSource  = users;
        }
Ejemplo n.º 3
0
        private bool GetSelectedValuesFromGUIRegister(out string email,
                                                      out string password)
        {
            bool readingAllOK = true;

            //retrieve email and password
            email = TextBoxRegistrationEmail.Text;
            if (string.IsNullOrEmpty(email))
            {
                Console.WriteLine("wrong email");
                readingAllOK = false;
            }
            else
            {
                try
                {
                    //todo this needs polishing
                    var addr = new System.Net.Mail.MailAddress(email);
                    readingAllOK = (addr.Address == email);
                }
                catch
                {
                    Console.WriteLine("wrong email");
                    readingAllOK = false;
                }
            }


            password = userPassword.Password;

            if (!UsersManagement.PasswordCorrect(password))
            {
                Console.WriteLine("wrong pswd");
                readingAllOK = false;
                //todo an explanation 'why' needed
            }

            return(readingAllOK);
        }
Ejemplo n.º 4
0
        public static void DecryptFile(EncryptionObject eo, string filePath, string decodedFileName, User selectedUser)
        {
            Console.WriteLine("decrypting");

            //todo temp

            /*string tempEncodedFilePath = "tempEncodedContents";
             * XmlHelpers.RetrieveXmlHeaderFromFile(filePath, out string xmlHeaderString, tempEncodedFilePath);
             *
             * XmlHelpers.ReadDataFromXMLHeader(xmlHeaderString,
             *  out string algorithm, out string keySize,
             *  out string blockSize, out string cipherMode,
             *  out string iv, out Dictionary<string, string> recipents,
             *  out string fileExtension);
             *
             */
            //recipents are kept in a dictionary as
            //<recipentEmail, encryptedUserSessionKey> pairs

            //to decrypt the file we need a session key
            //we need to find selectedUser- the user that current user of the app claims to be-
            //get their encryptedUserSessionKey
            //and decrypt the key using user's private key

            //todo maybe set to some noise, so that if foreach doesn't find anything, the decoding will work and produce noise-file

            //todo temp

            /*string encryptedSessionKeyString ="aaaa";
             * foreach(KeyValuePair<string, string> emailKey in recipents)
             * {
             *  if (emailKey.Key.Equals(selectedUser.Email))
             *  {
             *      encryptedSessionKeyString = emailKey.Value;
             *      break;
             *  }
             * }
             *
             * //decrypt session key using user's private key
             * string userPrivateKeyString = UsersManagement.GetUserPrivateKeyFromFile(selectedUser.Email);
             *
             * byte[] decryptedSessionKeyByte = EncryptionHelper.DecryptSessionKeyFromString(encryptedSessionKeyString, userPrivateKeyString);
             */

            //todo temp to remove
            string userPrivateKeyString = UsersManagement.GetUserPrivateKeyFromFile(selectedUser.Email);

            byte[] decryptedSessionKeyByte = EncryptionHelper.DecryptSessionKeyFromString(eo.encryptedSessionKey, userPrivateKeyString);
            Console.WriteLine("private key of " + selectedUser.Email + " is " + userPrivateKeyString);

            CipherMode mode = CipherMode.CBC;

            EncryptionHelper.AesDecryptToFile(filePath,
                                              decodedFileName + ".txt",
                                              decryptedSessionKeyByte, mode, eo.blockSize,
                                              Convert.FromBase64String(eo.ivString));


            //set cipher mode
            //todo uncomment

            /*CipherMode mode = CipherMode.CBC;
             *
             * switch (cipherMode)
             * {
             *  case Globals.modeCBC:
             *      mode = CipherMode.CBC;
             *      break;
             *  case Globals.modeCFB:
             *      mode = CipherMode.CFB;
             *      break;
             *  case Globals.modeECB:
             *      mode = CipherMode.ECB;
             *      break;
             *  case Globals.modeOFB:
             *      mode = CipherMode.OFB;
             *      break;
             *
             * }
             *
             * EncryptionHelper.AesDecryptToFile(tempEncodedFilePath,
             *  decodedFileName + fileExtension,
             *  decryptedSessionKeyByte, mode, Int32.Parse(keySize), //not key size, should be block size!
             *  Convert.FromBase64String(iv));
             */
        }