Пример #1
0
        private void butDecrypt_Click(object sender, EventArgs e)
        {
            String      strInput    = txtInput.Text.Trim();
            String      strOutput   = txtOutput.Text.Trim();
            String      strPassword = txtPassword.Text;
            string      strIV       = txtIV.Text;
            PaddingMode PM          = (PaddingMode)cmbPaddingMode.SelectedItem;
            CipherMode  CM          = (CipherMode)cmbModeofOperation.SelectedItem;
            int         iKeySize    = (rB128.Checked == true) ? 128 : 192;

            if (strPassword.Length * 8 != iKeySize)
            {
                MessageBox.Show("Chiều dài của mật khẩu phải là " + string.Format("{0}", iKeySize / 8));
                return;
            }

            if (strIV.Length != 8 && (CM != CipherMode.ECB))
            {
                MessageBox.Show("Chiều dài của IV phải là 8 ký tự.");
                txtIV.Select(0, strIV.Length);
                txtIV.Focus();
                return;
            }

            if (CM == CipherMode.ECB)
            {
                strIV = "12345678";
            }

            try
            {
                CTripleDES TDES = new CTripleDES(strPassword, iKeySize, strIV, PM, CM);
                TDES.DecryptFile(strInput, strOutput);
                MessageBox.Show("Giải mã thành công");
            }
            catch (System.Exception e1)
            {
                MessageBox.Show("Lỗi: \n" + e1.Message);
            }
        }
Пример #2
0
        private void butDecrypt_Click(object sender, EventArgs e)
        {
            String strInput    = txtInput.Text.Trim();
            String strOutput   = txtOutput.Text.Trim();
            String strPassword = txtPassword.Text;
            int    iKeySize    = (rB128.Checked == true) ? 128 : 192;

            if (strPassword.Length * 8 != iKeySize)
            {
                MessageBox.Show("Chiều dài của mật khẩu phải là " + string.Format("{0}", iKeySize / 8));
                return;
            }

            try
            {
                CTripleDES.DecryptFile(strInput, strOutput, strPassword, iKeySize);
                MessageBox.Show("Giải mã thành công");
            }
            catch (System.Exception e1)
            {
                MessageBox.Show("Lỗi: \n" + e1.Message);
            }
        }