Example #1
0
        private void DecKeyIvCallback(byte[] key, byte[] iv, byte[] hash)
        {
            if (doCacnel)
            {
                return;
            }
            string intxt = "", outtxt = "";

            Dispatcher.Invoke(() =>
            {
                if (doCacnel)
                {
                    return;
                }
                if (key == null)
                {
                    statusBox.Text += "手机已拒绝\n";
                    tryCancel();
                }
                else
                {
                    statusBox.Text += "开始解密……\n";
                    intxt           = inputFile.Text;
                    outtxt          = outputFile.Text;
                }
            });
            if (key == null)
            {
                return;
            }
            byte[] rethash = ClientLib.Dec(intxt, outtxt, key, iv);
            if (rethash == null)
            {
                Dispatcher.Invoke(() =>
                {
                    statusBox.Text += "解密失败\n";
                    File.Delete(outputFile.Text);
                    tryCancel();
                });
            }
            else
            {
                if (!Enumerable.SequenceEqual(hash, rethash))
                {
                    Dispatcher.Invoke(() =>
                    {
                        statusBox.Text += "校验错误,解密失败\n";
                        File.Delete(outputFile.Text);
                        tryCancel();
                    });
                }
                else
                {
                    Dispatcher.Invoke(() =>
                    {
                        statusBox.Text += "解密完成\n";
                        statusBox.Text += inputFile.Text + " -> " + outputFile.Text + "\n";
                        tryCancel(true);
                    });
                }
            }
        }
Example #2
0
        private void EncKeyIvCallback(byte[] key, byte[] iv, byte[] hash)
        {
            if (doCacnel)
            {
                return;
            }
            string intxt = "", outtxt = "";

            Dispatcher.Invoke(() =>
            {
                if (doCacnel)
                {
                    return;
                }
                if (key == null)
                {
                    statusBox.Text += "手机已拒绝\n";
                    tryCancel();
                }
                else
                {
                    statusBox.Text += "开始加密……\n";
                    intxt           = inputFile.Text;
                    outtxt          = outputFile.Text;
                }
            });
            if (key == null)
            {
                return;
            }
            byte[] rethash = ClientLib.Enc(intxt, outtxt, key, iv);
            if (rethash == null)
            {
                Dispatcher.Invoke(() =>
                {
                    statusBox.Text += "加密失败\n";
                    File.Delete(outputFile.Text);
                    tryCancel();
                });
            }
            else
            {
                if (!conn.SendHash(rethash))
                {
                    Dispatcher.Invoke(() =>
                    {
                        statusBox.Text += "手机失去连接,加密失败\n";
                        File.Delete(outputFile.Text);
                        tryCancel();
                    });
                }
                else
                {
                    Dispatcher.Invoke(() =>
                    {
                        statusBox.Text += "加密完成\n";
                        statusBox.Text += inputFile.Text + " -> " + outputFile.Text + "\n";
                        tryCancel(true);
                    });
                }
            }
        }