Пример #1
0
        private async void HideInformation()
        {
            if (textForHide.Length > 0)
            {
                sourceString    = textForHide;
                TimeForCrypting = string.Empty;

                //if(RandomCheckBox.IsChecked)
                //    CurrentShift = 0;

                string pathToNewFile = DocumentHelper.CopyFile(pathToDirOrigFile, filenameOrigFile);
                bool   isSuccesful   = false;

                Stopwatch.Restart();
                sourceString = SelectedCryptMethod?.Encrypt(sourceString, pathToDirOrigFile) ?? sourceString;

                var hash = SelectedHashMethod?.GetHash(SelectedCryptMethod == null ? sourceString : Converter.BinaryToString(sourceString));
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    MD5.SaveHash(pathToDirOrigFile, hash); //Mocked until base class will not be implemented
                }

                sourceString = SelectedCodMethod?.Coding(SelectedCryptMethod != null ? sourceString : Converter.StringToBinary(sourceString)) ?? sourceString;

                if (SelectedCryptMethod == null && SelectedCodMethod == null)
                {
                    sourceString = Converter.StringToBinary(sourceString);
                }

                HideFontModel codeModel = new HideFontModel(pathToNewFile);
                isSuccesful = await codeModel.HideInformation(sourceString.ToCharArray(), CurrentShift, RandomCheckBox.IsChecked, VisibleColorCheckBox.IsChecked, OneFontName, ZeroFontName);

                Stopwatch.Stop();
                TimeForCrypting = Math.Round(Stopwatch.Elapsed.TotalSeconds, 2).ToString() + " сек.";

                if (isSuccesful)
                {
                    ShowMetroMessageBox("Информация", "Скрытие информации прошло успешно.\n\nПуть к измененному файлу: " + pathToNewFile);
                    KeyStatus      = (SelectedCryptMethod != null) ? "сгенерирован" : "выключен";
                    KeyStatusColor = (SelectedCryptMethod != null) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Black);
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Во время выполнения произошла ошибка.");
                    KeyStatus      = (SelectedCryptMethod != null) ? "ошибка генерации" : "выключен RSA";
                    KeyStatusColor = (SelectedCryptMethod != null) ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
                }
            }
            else
            {
                ShowMetroMessageBox("Ошибка", "Введите текст.");
            }
            //TextForHide = String.Empty;
        }
Пример #2
0
        protected string messageTransformation(string message)
        {
            bool?isHashValid = SelectedHashMethod?.VerifyHash(message, hashFile);

            if (isHashValid != null && isHashValid == false)
            {
                return(null);
            }

            message = SelectedCodMethod?.DeCoding(message) ?? message;
            message = SelectedCryptMethod?.Decrypt(message, CryptFile) ?? message;

            return(message);
        }
        private void HideInformation()
        {
            if (textForHide.Length > 0)
            {
                sourceString = textForHide;

                if (SmartHidingCheckBox.IsChecked)
                {
                    ShowMetroMessageBox("Предупреждение", "При выбранном умном скрытии автоматически будет включена псевдорандомизация, \n\tа визуальное выделение отключено!\n");
                    RandomCheckBox.IsChecked       = true;
                    VisibleColorCheckBox.IsChecked = false;
                }
                string pathToNewFile = DocumentHelper.CopyFile(pathToDirOrigFile, filenameOrigFile);
                bool   isSuccesful   = false;

                Stopwatch.Restart();
                sourceString = SelectedCryptMethod?.Encrypt(sourceString, pathToDirOrigFile) ?? sourceString;

                var hash = SelectedHashMethod?.GetHash(SelectedCryptMethod == null ? sourceString : Converter.BinaryToString(sourceString));
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    MD5.SaveHash(pathToDirOrigFile, hash); //Mocked until base class will not be implemented
                }

                sourceString = SelectedCodMethod?.Coding(SelectedCryptMethod != null ? sourceString : Converter.StringToBinary(sourceString)) ?? sourceString;

                HideAproshModel codeModel = new HideAproshModel(pathToNewFile);
                isSuccesful = codeModel.HideInformation(sourceString.ToCharArray(), VisibleColorCheckBox.IsChecked, RandomCheckBox.IsChecked, ZeroBitSpacing, SoloBitSpacing);


                Stopwatch.Stop();
                TimeForCrypting = Math.Round(Stopwatch.Elapsed.TotalSeconds, 2).ToString() + " сек.";

                if (isSuccesful)
                {
                    ShowMetroMessageBox("Информация", "Скрытие информации прошло успешно.\n\nПуть к измененному файлу: " + pathToNewFile);
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Во время выполнения произошла ошибка.");
                }
            }
            else
            {
                ShowMetroMessageBox("Ошибка", "Введите текст.");
            }
        }
Пример #4
0
        private async void OpenForDecode()
        {
            try
            {
                if (string.IsNullOrEmpty(PathToDoc))
                {
                    ShowMetroMessageBox("Информация", "Загрузите файл для извлечения");
                    return;
                }

                CryptedText      = string.Empty;
                SearchedText     = string.Empty;
                TimeForDerypting = string.Empty;

                Stopwatch.Restart();
                ShowFontModel codeModel        = new ShowFontModel(PathToDoc);
                string        foundedBitsInDoc = await codeModel.FindInformation(OneFontName, ZeroFontName);

                SearchedText = SelectedCodMethod == null ? SearchedText = Converter.BinaryToString(foundedBitsInDoc) : foundedBitsInDoc;

                if (SelectedCodMethod != null)
                {
                    EncodedText = SearchedText;

                    SearchedText = Converter.BinaryToString(SelectedCodMethod.DeCoding(SearchedText));
                }

                if (SelectedHashMethod != null)
                {
                    if (string.IsNullOrEmpty(HashFile))
                    {
                        ShowMetroMessageBox("Информация", "Нет файла с хэшем!");
                        return;
                    }

                    var isHashSame = SelectedHashMethod.VerifyHash(SearchedText, HashFile);

                    if (!isHashSame)
                    {
                        ShowMetroMessageBox("Информация", "Не валидный хэш!");
                        return;
                    }
                }

                if (SelectedCryptMethod != null)
                {
                    CryptedText = SearchedText;

                    if (string.IsNullOrEmpty(CryptFile))
                    {
                        ShowMetroMessageBox("Информация", "Нет файла с приватным ключом!");
                        return;
                    }

                    SearchedText = SelectedCryptMethod?.Decrypt(SearchedText, CryptFile) ?? SearchedText;

                    if (string.IsNullOrEmpty(SearchedText))
                    {
                        ShowMetroMessageBox("Информация", "Ключ не подходит.");
                        return;
                    }
                }
                Stopwatch.Stop();
                TimeForDerypting = Math.Round(Stopwatch.Elapsed.TotalSeconds, 2).ToString() + " сек.";

                if (SearchedText.Length > 0)
                {
                    ShowMetroMessageBox("Информация", "Извлечение информации из файла " + PathToDoc.Split('\\').LastOrDefault() + " прошло успешно.");
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Файл " + PathToDoc.Split('\\').LastOrDefault() + " не содержит скрытой информации.");
                }
            }
            catch (Exception e)
            {
                ShowMetroMessageBox("Информация", e.Message + "\n " + e.InnerException + "\n" + "\n" + e.Source);
            }
        }
Пример #5
0
        //private void OpenDocument()
        //{
        //    if (OpenFileDialog(openFileDialog) != null)
        //    {
        //        FullPathToOrigFile = openFileDialog.FileName;
        //        filenameOrigFile = openFileDialog.SafeFileName;
        //        pathToDirOrigFile = fullPathToOrigFile.Substring(0, fullPathToOrigFile.Length - filenameOrigFile.Length);

        //        CountLettersIsCanHide = HideColorModel.HowMuchLettersICanHide(fullPathToOrigFile).ToString();
        //        maxLettersIsCanHide = Int32.Parse(countLettersIsCanHide);
        //        if (Int32.Parse(countLettersIsCanHide) > 0)
        //        {
        //            IsTextForHideEnabled = true;
        //            IsHideInformationButtonEnabled = true;

        //            RandomCheckBox.IsEnabled = true;
        //            RSACheckBox.IsEnabled = true;
        //            AdditionalBitsCheckBox.IsEnabled = true;
        //            VisibleColorCheckBox.IsEnabled = true;
        //            SmartHidingCheckBox.IsEnabled = true;
        //        }
        //        else
        //        {
        //            ShowMetroMessageBox("Ошибка", "В данном файле невозможно скрыть информацию.");
        //        }
        //    }
        //}

        private async void HideInformation()
        {
            if (textForHide.Length > 0)
            {
                sourceString = textForHide;

                if (SmartHidingCheckBox.IsChecked)
                {
                    ShowMetroMessageBox("Предупреждение", "При выбранном умном скрытии автоматически будет включена псевдорандомизация, \n\tа визуальное выделение отключено!\n");
                    RandomCheckBox.IsChecked       = true;
                    VisibleColorCheckBox.IsChecked = false;
                }
                string pathToNewFile = DocumentHelper.CopyFile(pathToDirOrigFile, filenameOrigFile);
                bool   isSuccesful   = false;

                //textForHide = (RSACheckBox.IsChecked)
                //    ? Converter.RsaCryptor(TextForHide, pathToDirOrigFile)
                //    : Converter.StringToBinary(TextForHide);

                //textForHide = (AdditionalBitsCheckBox.IsChecked)
                //    ? HideColorModel.AddAdditionalBits(textForHide)
                //    : textForHide;
                Stopwatch.Restart();
                sourceString = SelectedCryptMethod?.Encrypt(sourceString, pathToDirOrigFile) ?? sourceString;

                var hash = SelectedHashMethod?.GetHash(SelectedCryptMethod == null ? sourceString : Converter.BinaryToString(sourceString));
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    MD5.SaveHash(pathToDirOrigFile, hash); //Mocked until base class will not be implemented
                }

                sourceString = SelectedCodMethod?.Coding(SelectedCryptMethod != null ? sourceString : Converter.StringToBinary(sourceString)) ?? sourceString;

                if (SelectedCryptMethod == null && SelectedCodMethod == null)
                {
                    sourceString = Converter.StringToBinary(sourceString);
                }

                HideColorModel codeModel = new HideColorModel(pathToNewFile);
                isSuccesful = await codeModel.HideInformation(sourceString.ToCharArray(), RandomCheckBox.IsChecked, VisibleColorCheckBox.IsChecked, SmartHidingCheckBox.IsChecked);

                Stopwatch.Stop();
                TimeForCrypting = Math.Round(Stopwatch.Elapsed.TotalSeconds, 2).ToString() + " сек.";

                if (isSuccesful)
                {
                    ShowMetroMessageBox("Информация", "Скрытие информации прошло успешно.\n\nПуть к измененному файлу: " + pathToNewFile);
                    //KeyStatus = (RSACheckBox.IsChecked == true) ? "сгенерирован" : "выключен RSA";
                    //KeyStatusColor = (RSACheckBox.IsChecked == true) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Black);
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Во время выполнения произошла ошибка.");
                    //KeyStatus = (RSACheckBox.IsChecked == true) ? "ошибка генерации" : "выключен RSA";
                    //KeyStatusColor = (RSACheckBox.IsChecked == true) ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
                }
            }
            else
            {
                ShowMetroMessageBox("Ошибка", "Введите текст.");
            }
            //TextForHide = String.Empty;
        }
        private async void OpenForDecode()
        {
            try
            {
                if (string.IsNullOrEmpty(PathToDoc))
                {
                    ShowMetroMessageBox("Информация", "Загрузите файл для извлечения");
                    return;
                }

                CryptedText = "";

                SearchedText1 = "";
                SearchedText  = "";

                ShowUnderlineModel codeModel        = new ShowUnderlineModel(PathToDoc);
                string             foundedBitsInDoc = await codeModel.FindInformation();



                //foundedBitsInDoc = AdditionalBitsCheckBox.IsChecked
                //     ? ShowUnderlineModel.RemoveAdditBits(foundedBitsInDoc)
                //     : foundedBitsInDoc;


                //foundedBitsInDoc = ShifrElGamalCheckBox.IsChecked
                //   ? ShowUnderlineModel.ShowUnderlineElGamal(foundedBitsInDoc)
                //   : foundedBitsInDoc;



                SearchedText = Converter.BinaryToString(foundedBitsInDoc);


                if (SelectedHashMethod != null)
                {
                    if (string.IsNullOrEmpty(HashFile))
                    {
                        ShowMetroMessageBox("Информация", "Нет файла с хэшем!");
                        return;
                    }

                    var isHashSame = SelectedHashMethod.VerifyHash(SearchedText, HashFile);



                    if (!isHashSame)
                    {
                        ShowMetroMessageBox("Информация", "Не валидный хэш!");
                        return;
                    }
                }

                if (SelectedCodMethod != null)
                {
                    SearchedText = Converter.BinaryToString(SelectedCodMethod.DeCoding(SearchedText));
                }

                if (SelectedCryptMethod != null)
                {
                    if (string.IsNullOrEmpty(RsaFile))
                    {
                        ShowMetroMessageBox("Информация", "Нет файла с приватным ключом!");
                        return;
                    }

                    SearchedText = SelectedCryptMethod?.Decrypt(SearchedText, RsaFile) ?? SearchedText;



                    if (string.IsNullOrEmpty(SearchedText))
                    {
                        ShowMetroMessageBox("Информация", "Ключ не подходит.");
                        return;
                    }
                }


                if (RsaOpenCheckBox.IsChecked)
                {
                    if (string.IsNullOrEmpty(RsaFile))
                    {
                        ShowMetroMessageBox("Информация", "Нет файла с приватным ключом!");
                        return;
                    }

                    CryptedText  = SearchedText;
                    SearchedText = await Converter.RsaDecryptor(SearchedText, RsaFile);

                    if (string.IsNullOrEmpty(SearchedText))
                    {
                        ShowMetroMessageBox("Информация", "Ключ не подходит.");
                        return;
                    }
                }



                if (SearchedText.Length > 0)
                {
                    ShowMetroMessageBox("Информация", "Извлечение информации из файла " + openFileDialog.SafeFileName + " прошло успешно.");
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Файл " + openFileDialog.SafeFileName + " не содержит скрытой информации.");
                }
            }
            catch (Exception e)
            {
                ShowMetroMessageBox("Информация", e.Message + "\n " + e.InnerException + "\n" + "\n" + e.Source);
            }
        }
        private async void HideInformation()
        {
            if (textForHide.Length > 0)
            {
                sourceString = textForHide;

                if (SmartHidingCheckBox.IsChecked)
                {
                    ShowMetroMessageBox("Предупреждение", "При выбранном умном скрытии автоматически будет включена псевдорандомизация, \n\tа визуальное выделение отключено!\n");
                    RandomCheckBox.IsChecked       = true;
                    VisibleColorCheckBox.IsChecked = false;
                }

                string pathToNewFile = DocumentHelper.CopyFile(pathToDirOrigFile, filenameOrigFile);
                bool   isSuccesful   = false;



                //textForHide = (RSACheckBox.IsChecked)
                //    ? Converter.RsaCryptor(TextForHide, pathToDirOrigFile)
                //    : Converter.StringToBinary(TextForHide);

                //MessageBox.Show("ee"+textForHide);

                //textForHide = (AdditionalBitsCheckBox.IsChecked)
                //    ? HideUnderlineModel.AddAdditionalBits(textForHide)
                //    : textForHide;

                //textForHide = Converter.StringToBinary(textForHide);



                //MessageBox.Show("ee1" + textForHide);

                //textForHide = (ShifrElGamalCheckBox.IsChecked)
                // ? HideUnderlineModel.HideUnderlineElGamal(textForHide)
                // : Converter.StringToBinary(TextForHide);

                //MessageBox.Show("text"+textForHide);


                textForHide = SelectedCryptMethod?.Encrypt(textForHide, pathToDirOrigFile)
                              ?? textForHide;

                //MessageBox.Show("криптаt" + textForHide);

                textForHide = SelectedCodMethod?.Coding(SelectedCryptMethod != null
                    ? textForHide : Converter.StringToBinary(TextForHide))
                              ?? TextForHide;
                MessageBox.Show(textForHide);

                //AttributeHidingModel codeModel = new AttributeHidingModel(pathToNewFile);
                //isSuccesful = await codeModel.HideInformation(textForHide.ToCharArray(), VisibleColorCheckBox.IsChecked, SelectedCodMethod != null, SelectedCryptMethod != null);

                HideUnderlineModel codeModel = new HideUnderlineModel(pathToNewFile);
                isSuccesful = await codeModel.HideInformation(textForHide.ToCharArray(), RandomCheckBox.IsChecked, VisibleColorCheckBox.IsChecked, OneFontName, ZeroFontName);


                var hash = SelectedHashMethod?.GetHash(SelectedCryptMethod == null || SelectedCodMethod != null ? TextForHide : Converter.BinaryToString(TextForHide)) ?? TextForHide;
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    MD5.SaveHash(pathToDirOrigFile, hash); //Mocked until base class will not be implemented
                }

                if (isSuccesful)
                {
                    ShowMetroMessageBox("Информация", "Скрытие информации прошло успешно.\n\nПуть к измененному файлу: " + pathToNewFile);
                    KeyStatus      = (RSACheckBox.IsChecked == true) ? "сгенерирован" : "выключен RSA";
                    KeyStatusColor = (RSACheckBox.IsChecked == true) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Black);
                }
                else
                {
                    ShowMetroMessageBox("Информация", "Во время выполнения произошла ошибка.");
                    KeyStatus      = (RSACheckBox.IsChecked == true) ? "ошибка генерации" : "выключен RSA";
                    KeyStatusColor = (RSACheckBox.IsChecked == true) ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
                }
            }
            else
            {
                ShowMetroMessageBox("Ошибка", "Введите текст.");
            }
            //TextForHide = String.Empty;
        }