コード例 #1
0
        private void DecryptMessage(object e, FileSystemEventArgs fsea)
        {
            string ext = Path.GetExtension(fsea.Name);

            if (!".aes".Equals(ext, StringComparison.CurrentCultureIgnoreCase) &&
                !".rc2".Equals(ext, StringComparison.CurrentCultureIgnoreCase) &&
                !".des3".Equals(ext, StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }
            string message;

            try
            {
                message = DecryptController.DecryptEncryptedFile(
                    DecryptController.EncryptedFileParametersParser(fsea.FullPath, locker));
            }
            catch (Exception exception)
            {
                MessageBox.Show("Message can't be decrypted! Exception : " + exception.Message, "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (message == null)
            {
                MessageBox.Show("Message can't be decrypted!", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Dispatcher?.Invoke(() => AddMessageUi(new Message(message, DateTime.Now, MessageProperty.Received)));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var pathToFile = FileButton.Content.ToString();

            try
            {
                _pathToDecryptedFile =
                    DecryptController.DecryptEncryptedFile(DecryptController.EncryptedFileParametersParser(pathToFile));
            }
            catch (Exception _)
            {
                MessageBox.Show("File can't be decrypted!", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (_pathToDecryptedFile != "")
            {
                MessageBox.Show("Congratulations, you successfully decrypted a file!");
                DecryptButton.IsEnabled    = false;
                FindFolderButton.IsEnabled = false;
                RunProgramButton.IsEnabled = false;
                new Thread(() =>
                {
                    Thread.Sleep(3000);
                    Dispatcher?.Invoke(() =>
                    {
                        FindFolderButton.IsEnabled = true;
                        RunProgramButton.IsEnabled = true;
                        return(DecryptButton.IsEnabled = true);
                    });
                }).Start();
            }
            else
            {
                MessageBox.Show("File can't be decrypted!", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }