public bool TestFileScheme()
        {
            FileScheme filescheme = new FileScheme();

            filescheme.File2Bytes("test.txt", "outEncoding.txt");
            Print("txt文件加密完成");
            filescheme.Bytes2File("outEncoding.txt", "outDecoding.txt");
            Print("txt文件解密完成");

            filescheme.File2Bytes("test.docx", "outEncoding.docx");
            Print("docx文件加密完成");
            filescheme.Bytes2File("outEncoding.docx", "outDecoding.docx");
            Print("docx文件解密完成");

            filescheme.File2Bytes("test.md", "outEncoding.md");
            Print("md文件加密完成");
            filescheme.Bytes2File("outEncoding.md", "outDecoding.md");
            Print("md文件解密完成");

            filescheme.File2Bytes("文本材料.docx", "文本材料加密.docx");
            Print("文本材料.docx加密完成");
            filescheme.Bytes2File("文本材料加密.docx", "文本材料解密.docx");
            Print("文本材料加密.docx解密完成");
            return(true);
        }
Пример #2
0
        private void ChooseFileButton_Click(object sender, MouseButtonEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.HasValue)
            {
                FileScheme fileScheme = new FileScheme();
                fileScheme.File2Bytes(fileDialog.FileName, fileDialog.FileName + ".cb");
            }
            this.Close();
        }
Пример #3
0
        public MainWindow()
        {
            InitializeComponent();

            /*
             * 右键快捷加密解密部分
             */
            var args = Environment.GetCommandLineArgs();

            if (args.Length > 2)
            {
                string originPath = args[2];                    //获取加密文件路径

                FileScheme fileScheme = new FileScheme();

                if (args[1] == "encrypt")                       //加密文件
                {
                    fileScheme.File2Bytes(originPath, originPath += ".cb");
                }
                else if (args[1] == "decrypt" && originPath.Contains(".cb"))                     //解密文件,且检查是否为加密过的文件
                {
                    int index = originPath.IndexOf(".cb");
                    fileScheme.Bytes2File(originPath, originPath.Remove(index, 3));
                }
            }

            /*创建或读入设置文件部分*/
            string xmlPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            xmlPath += "settings.xml";
            if (!File.Exists(xmlPath))
            {
                XMLSaveAndRead xmlHandle = new XMLSaveAndRead();

                //存储信息
                List <Settings> info     = new List <Settings>();
                Settings        settings = new Settings(false, true, ("crtl", "E"), "3", SchemeType.Caesar, SchemeType.RailFence, SchemeType.Substitution);          //默认配置
                info.Add(settings);
                //将info的类型List<Test>和自身info传入
                string xmlInfo = xmlHandle.SerializeObject <List <Settings> >(info);
                xmlHandle.CreateXML(xmlPath, xmlInfo);
                CommonData.settings = settings;
            }
            else
            {
                XMLSaveAndRead  xmlHandle = new XMLSaveAndRead();
                string          doc       = xmlHandle.LoadXML(xmlPath);
                List <Settings> info1     = (List <Settings>)xmlHandle.DeserializeObject <List <Settings> >(doc);
                for (int i = 0; i < info1.Count; i++)
                {
                    CommonData.settings.isAutoStart    = info1[i].isAutoStart;
                    CommonData.settings.isUsingServer  = info1[i].isUsingServer;
                    CommonData.settings.shortCutKey    = info1[i].shortCutKey;
                    CommonData.settings.clipDefaultKey = info1[i].clipDefaultKey;
                    CommonData.settings.encryptType    = info1[i].encryptType;
                    CommonData.settings.decryptType    = info1[i].decryptType;
                    CommonData.settings.breakType      = info1[i].breakType;
                }
            }

            this.TaskListBox.ItemsSource = CommonData.Tasks;

            SqliteClient dbClient = new SqliteClient(CommonData.DbSource);

            dbClient.Open();
            var taskList = dbClient.QueryAllTask();

            foreach (var task in taskList)
            {
                CommonData.Tasks.Add(task);
            }
            dbClient.Close();

            //DebugWindow debugWindow = new DebugWindow();
            //debugWindow.Show();
        }