Beispiel #1
0
        /// <summary>
        /// Decryption start.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDecrypt_Click(object sender, EventArgs e)
        {
            buttonDecrypt.Enabled = false;
            checkBoxNotMaskPassword.Visible = false;
            progressBar1.Location = textBox1.Location;
            progressBar1.Width = textBox1.Width;
            progressBar1.Visible = true;
            labelPercent.Text = "- %";

            //-----------------------------------
            // Directory to oputput decrypted files
            //-----------------------------------
            string OutDirPath = Path.GetDirectoryName(Application.ExecutablePath);

            //-----------------------------------
            // Decryption password
            //-----------------------------------
            string DecryptionPassword = textBox1.Text;

            //-----------------------------------
            // Password file
            //-----------------------------------

            // Drag & Drop Password file
            byte[] DecryptionPasswordBinary = null;
            if (File.Exists(TempDecryptionPassFilePath) == true)
            {
                DecryptionPasswordBinary = GetPasswordFileHash3(TempDecryptionPassFilePath);
            }

            //-----------------------------------
            // Preparing for decrypting
            //
            //-----------------------------------
            decryption = new FileDecrypt3(Application.ExecutablePath);

            if (decryption.TokenStr == "_AttacheCaseData")
            {
                // Encryption data ( O.K. )
            }
            else if (decryption.TokenStr == "_Atc_Broken_Data")
            {
            //
            // エラー
            // この暗号化ファイルは壊れています。処理を中止します。
            //
            // Alert
            // This encrypted file is broken. The process is aborted.
            //
            string DialogTitleAlert = "Alert";
            string DialogMessageAtcFileBroken = "This encrypted file is broken. The process is aborted.";

            if (CurrentCultureName == "ja")
            {
              DialogTitleAlert = "エラー";
              DialogMessageAtcFileBroken = "この暗号化ファイルは壊れています。処理を中止します。";
            }
            MessageBox.Show(DialogMessageAtcFileBroken,	DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            if (CurrentCultureName == "ja")
            {
              labelMessage.Text = "復号処理を中止しました。";
            }
            else
            {
              labelMessage.Text = "Process of decryption has been aborted.";
            }
            labelPercent.Text = "- %";

            return;
            }
            else
            {
            //
            // エラー
            // 暗号化ファイルではありません。処理を中止します。
            //
            // Alert
            // The file is not encrypted file. The process is aborted.
            //
            string DialogTitleAlert = "Alert";
            string DialogMessageNotAtcFile = "The file is not encrypted file. The process is aborted.";
            if (CurrentCultureName == "ja")
            {
              DialogTitleAlert = "エラー";
              DialogMessageNotAtcFile = "暗号化ファイルではありません。処理を中止します。";
            }
            MessageBox.Show(DialogMessageNotAtcFile, DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            if (CurrentCultureName == "ja")
            {
              labelMessage.Text = "復号処理を中止しました。";
            }
            else
            {
              labelMessage.Text = "Process of decryption has been aborted.";
            }
            labelPercent.Text = "- %";

            return;
            }

            if (LimitOfInputPassword == -1)
            {
                LimitOfInputPassword = decryption.MissTypeLimits;
            }

            #if (DEBUG)
              System.Windows.Forms.MessageBox.Show("BackgroundWorker event handler.");
            #endif
              //======================================================================
              // BackgroundWorker event handler
              bkg = new BackgroundWorker();
            bkg.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
            bkg.ProgressChanged += backgroundWorker_ProgressChanged;
            bkg.WorkerReportsProgress = true;

            #if (DEBUG)
              System.Windows.Forms.MessageBox.Show("Decryption start.");
            #endif
              //======================================================================
              // Decryption start
              // 復号開始
              // Refer:http://stackoverflow.com/questions/4807152/sending-arguments-to-background-worker
              //======================================================================
              bkg.DoWork += (s, d) =>
            {
                decryption.Decrypt(
                    s, d,
                    Application.ExecutablePath, OutDirPath, DecryptionPassword, DecryptionPasswordBinary,
                    DialogMessageForOverWrite);
            };

            bkg.RunWorkerAsync();
        }
Beispiel #2
0
        //======================================================================
        /// <summary>
        /// DecryptionProcess
        /// </summary>
        //======================================================================
        private void DecryptionProcess()
        {
            //-----------------------------------
              // Display progress window
              //-----------------------------------
              panelStartPage.Visible = false;
              panelEncrypt.Visible = false;
              panelEncryptConfirm.Visible = false;
              panelDecrypt.Visible = false;
              panelProgressState.Visible = true;

              labelProgress.Text = labelDecryption.Text;
              pictureBoxProgress.Image = pictureBoxDecOn.Image;
              labelCryptionType.Text = Resources.labelProcessNameDecrypt;
              buttonCancel.Text = Resources.ButtonTextCancel;

              this.Update();

              if (FileIndex > AppSettings.Instance.FileList.Count - 1)
              {
            labelProgressPercentText.Text = "100%";
            progressBar.Style = ProgressBarStyle.Continuous;
            progressBar.Value = progressBar.Maximum;
            labelCryptionType.Text = "";
            labelProgressMessageText.Text = Resources.labelCaptionCompleted;  // "Completed"
            notifyIcon1.Text = "100% " + Resources.labelCaptionCompleted;
            buttonCancel.Text = Resources.ButtonTextOK;

            DecryptionEndProcess();

            return;
              }

              //-----------------------------------
              // Directory to oputput decrypted files
              //-----------------------------------
              string OutDirPath = "";
              if (AppSettings.Instance.fDecodeToSameFldr == true)
              {
            OutDirPath = AppSettings.Instance.DecodeToSameFldrPath;
              }

              if (Directory.Exists(OutDirPath) == false)
              {
            OutDirPath = Path.GetDirectoryName((string)AppSettings.Instance.FileList[0]);
              }

              //-----------------------------------
              // Decryption password
              //-----------------------------------
              string DecryptionPassword = "";
              if (AppSettings.Instance.fMyDecryptPasswordKeep == true && LimitOfInputPassword == -1)
              {
            DecryptionPassword = AppSettings.Instance.MyDecryptPasswordString;
              }
              else
              {
            DecryptionPassword = textBoxDecryptPassword.Text;
              }

              //-----------------------------------
              // Always minimize when running
              //-----------------------------------
              if (AppSettings.Instance.fMainWindowMinimize == true)
              {
            this.WindowState = FormWindowState.Minimized;
              }

              //-----------------------------------
              // Minimizing a window without displaying in the taskbar
              //-----------------------------------
              if (AppSettings.Instance.fTaskBarHide == true)
              {
            this.Hide();
              }

              //-----------------------------------
              // Display in the task tray
              //-----------------------------------
              if (AppSettings.Instance.fTaskTrayIcon == true)
              {
            notifyIcon1.Visible = true;
              }
              else
              {
            notifyIcon1.Visible = false;
              }

              //-----------------------------------
              // Preparing for decrypting
              //
              //-----------------------------------
              string AtcFilePath = AppSettings.Instance.FileList[FileIndex];

              progressBar.Style = ProgressBarStyle.Marquee;
              progressBar.MarqueeAnimationSpeed = 50;
              // 復号するための準備をしています...
              // Getting ready for decryption...
              labelProgressMessageText.Text = Resources.labelGettingReadyForDecryption;

              decryption3 = new FileDecrypt3(AtcFilePath);

              if (decryption3.DataFileVersion < 130)
              {
            decryption2 = new FileDecrypt2(AtcFilePath);
              }

              if (decryption3.TokenStr == "_AttacheCaseData" || (decryption2 != null && decryption2.TokenStr == "_AttacheCaseData"))
              {
            // Encryption data ( O.K. )
              }
              else if (decryption3.TokenStr == "_Atc_Broken_Data" || (decryption2 != null && decryption2.TokenStr == "_Atc_Broken_Data"))
              {
            // エラー
            // この暗号化ファイルは破壊されています。処理を中止します。
            //
            // Alert
            // This encrypted file is broken. The process is aborted.
            MessageBox.Show(new Form { TopMost = true }, Resources.DialogMessageAtcFileBroken + Environment.NewLine + AtcFilePath,
            Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            labelProgressPercentText.Text = "- %";
            labelProgressMessageText.Text = Resources.labelCaptionAborted;
            progressBar.Value = 0;
            progressBar.Style = ProgressBarStyle.Continuous;
            buttonCancel.Text = Resources.ButtonTextOK;
            notifyIcon1.Text = "- % " + Resources.labelCaptionError;

            return;

              }
              else
              {
            // エラー
            // 暗号化ファイルではありません。処理を中止します。
            //
            // Alert
            // The file is not encrypted file. The process is aborted.
            MessageBox.Show(new Form { TopMost = true }, Resources.DialogMessageNotAtcFile + Environment.NewLine + AtcFilePath,
            Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            labelProgressPercentText.Text = "- %";
            labelProgressMessageText.Text = Resources.labelCaptionAborted;
            progressBar.Value = 0;
            progressBar.Style = ProgressBarStyle.Continuous;
            buttonCancel.Text = Resources.ButtonTextOK;
            notifyIcon1.Text = "- % " + Resources.labelCaptionError;
            return;

              }

              //-----------------------------------
              // Password file
              //-----------------------------------

              // ※パスワードファイルは、記憶パスワードよりも優先される。
              // * This password files is priority than memorized encryption password.

              byte[] DecryptionPasswordBinary = null;
              if (AppSettings.Instance.fAllowPassFile == true)
              {
            // Check specified password file for Decryption
            if (AppSettings.Instance.fCheckPassFileDecrypt == true)
            {
              if (File.Exists(AppSettings.Instance.PassFilePathDecrypt) == true)
              {
            if (decryption3.DataFileVersion < 130)
            {
              DecryptionPasswordBinary = GetPasswordFileHash2(AppSettings.Instance.PassFilePathDecrypt);
            }
            else
            {
              DecryptionPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.PassFilePathDecrypt);
            }
              }
              else
              {
            if (AppSettings.Instance.fNoErrMsgOnPassFile == false)
            {
              // エラー
              // 復号時の指定されたパスワードファイルが見つかりません。処理を中止します。
              //
              // Error
              // The specified password file is not found in decryption. The process is aborted.
              DialogResult ret = MessageBox.Show(
                new Form { TopMost = true },
                Resources.DialogMessageDecryptionPasswordFileNotFound + Environment.NewLine + AppSettings.Instance.PassFilePathDecrypt,
                Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

              labelProgressPercentText.Text = "- %";
              labelProgressMessageText.Text = Resources.labelCaptionAborted;
              progressBar.Value = 0;
              progressBar.Style = ProgressBarStyle.Continuous;
              buttonCancel.Text = Resources.ButtonTextOK;
              notifyIcon1.Text = "- % " + Resources.labelCaptionError;

              return;
            }
              }
            }

            // Drag & Drop Password file
            if (File.Exists(AppSettings.Instance.TempDecryptionPassFilePath) == true)
            {
              if (decryption3.DataFileVersion < 130)
              {
            DecryptionPasswordBinary = GetPasswordFileHash2(AppSettings.Instance.TempDecryptionPassFilePath);
            DecryptionPassword = "";
              }
              else
              {
            DecryptionPasswordBinary = GetPasswordFileHash3(AppSettings.Instance.TempDecryptionPassFilePath);
            DecryptionPassword = "";
              }
            }

            // コマンドラインからのパスワードがさらに優先される
            // The password from command line option that is still more priority.
            if (AppSettings.Instance.DecryptPasswordStringFromCommandLine != null ||
            AppSettings.Instance.DecryptPasswordStringFromCommandLine != null)
            {
              DecryptionPassword = AppSettings.Instance.DecryptPasswordStringFromCommandLine;
              DecryptionPasswordBinary = null;
            }

              }

              // BackgroundWorker event handler
              bkg = new BackgroundWorker();
              bkg.RunWorkerCompleted += backgroundWorker_Decryption_RunWorkerCompleted;
              bkg.ProgressChanged += backgroundWorker_ProgressChanged;
              bkg.WorkerReportsProgress = true;
              bkg.WorkerSupportsCancellation = true;

              //-----------------------------------
              // Old version
              if (decryption3.DataFileVersion < 130)
              {
            decryption3 = null; // ver.3 is null
            decryption2 = new FileDecrypt2(AtcFilePath);
            decryption2.fNoParentFolder = AppSettings.Instance.fNoParentFldr;
            decryption2.NumberOfFiles = FileIndex + 1;
            decryption2.fSameTimeStamp = AppSettings.Instance.fSameTimeStamp;
            decryption2.TotalNumberOfFiles = AppSettings.Instance.FileList.Count;
            decryption2.TempOverWriteOption = (AppSettings.Instance.fDecryptConfirmOverwrite == false ? OVERWRITE_ALL : 0);
            if (LimitOfInputPassword == -1)
            {
              LimitOfInputPassword = decryption2.MissTypeLimits;
            }
            toolStripStatusLabelDataVersion.Text = "Data ver.2";
            this.Update();

            //======================================================================
            // Decryption start
            // 復号開始
            // http://stackoverflow.com/questions/4807152/sending-arguments-to-background-worker
            //======================================================================
            bkg.DoWork += (s, d) =>
            {
              decryption2.Decrypt(
            s, d,
            AtcFilePath, OutDirPath, DecryptionPassword, DecryptionPasswordBinary,
            DialogMessageForOverWrite);
            };

            bkg.RunWorkerAsync();

              }
              //-----------------------------------
              // Current version
              else if (decryption3.DataFileVersion < 140)
              {
            decryption2 = null;
            decryption3.fNoParentFolder = AppSettings.Instance.fNoParentFldr;
            decryption3.NumberOfFiles = FileIndex + 1;
            decryption3.TotalNumberOfFiles = AppSettings.Instance.FileList.Count;
            decryption3.fSameTimeStamp = AppSettings.Instance.fSameTimeStamp;
            decryption3.TempOverWriteOption = (AppSettings.Instance.fDecryptConfirmOverwrite == false ? OVERWRITE_ALL : 0);
            if (LimitOfInputPassword == -1)
            {
              LimitOfInputPassword = decryption3.MissTypeLimits;
            }
            toolStripStatusLabelDataVersion.Text = "Data ver.3";
            this.Update();

            //======================================================================
            // Decryption start
            // 復号開始
            // http://stackoverflow.com/questions/4807152/sending-arguments-to-background-worker
            //======================================================================
            bkg.DoWork += (s, d) =>
            {
              decryption3.Decrypt(
            s, d,
            AtcFilePath, OutDirPath, DecryptionPassword, DecryptionPasswordBinary,
            DialogMessageForOverWrite);
            };

            bkg.RunWorkerAsync();

              }
              //-----------------------------------
              // Higher version
              else
              {
            // 警告
            // このファイルはアタッシェケースの上位バージョンで暗号化されています。
            // 復号できません。処理を中止します。
            //
            // Alert
            // This file has been encrypted with a higher version.
            // It can not be decrypted. The process is aborted.
            MessageBox.Show(new Form { TopMost = true }, Resources.DialogMessageHigherVersion + Environment.NewLine + AtcFilePath,
            Resources.DialogTitleAlert, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            labelProgressPercentText.Text = "- %";
            labelProgressMessageText.Text = Resources.labelCaptionAborted;
            progressBar.Value = 0;
            progressBar.Style = ProgressBarStyle.Continuous;
            buttonCancel.Text = Resources.ButtonTextOK;
            notifyIcon1.Text = "- % " + Resources.labelCaptionError;

            return;

              }
        }