Пример #1
0
        private void _file_encrypt()
        {
            if (_key_manager == null)
            {
                return;
            }
            try
            {
                if (_key_manager.IsDynamicEncryption)
                {
                    FileEncrypt.EncryptFile(_local_path, _local_path + ".encrypted", _key_manager.RSAPublicKey, _local_data.SHA1, _file_encrypt_status_callback);
                }
                else if (_key_manager.IsStaticEncryption)
                {
                    FileEncrypt.EncryptFile(_local_path, _local_path + ".encrypted", _key_manager.AESKey, _key_manager.AESIV, _local_data.SHA1, _file_encrypt_status_callback);
                }
                else
                {
                    throw new Exception("密钥缺失");
                }

                _local_path += ".encrypted";
                if (!_remote_path.EndsWith(".bcsd"))
                {
                    _remote_path += ".bcsd";
                }
            }
            catch (Exception ex)
            {
                Tracer.GlobalTracer.TraceError(ex);
            }
        }
Пример #2
0
        //将txt文件加密、改变后缀、隐藏文件及其父文件夹/
        public static void EncryptionFile(string filePath, string mixedExtension, string encryptKey)
        {
            string sourcefileName = filePath;

            if (!File.Exists(sourcefileName))
            {
                return;
            }

            FileEncrypt.EncryptFile(sourcefileName, encryptKey, (int max, int value) => { });
            string destfileName = System.IO.Path.ChangeExtension(sourcefileName, mixedExtension);

            File.Move(sourcefileName, destfileName);
            File.SetAttributes(destfileName, FileAttributes.Hidden | FileAttributes.System);

            string folderPath = new FileInfo(sourcefileName).DirectoryName;

            File.SetAttributes(folderPath, FileAttributes.System); //设置添加系统文件夹/
            File.SetAttributes(folderPath, FileAttributes.Hidden); //设置添加隐藏文件夹/
        }
Пример #3
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            #region 验证
            if (txtPwd.Text == "")
            {
                MessageBox.Show("密码不能为空", "提示");
                return;
            }

            if (txtPwdCfm.Text == "")
            {
                MessageBox.Show("xwuser密码不能为空", "提示");
                return;
            }

            #endregion

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
                {
                    try
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            pbFile.Value            = 0;
                            lblProgressFile.Text    = "0%";
                            pbDir.Visible           = false;
                            lblProgressDir.Visible  = false;
                            pbFile.Visible          = false;
                            lblProgressFile.Visible = false;
                            lblShowPath.Text        = "加密文件:" + openFileDialog1.FileName;
                            lblShowPath.Visible     = true;
                            DisableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                        DateTime t1 = DateTime.Now;
                        FileEncrypt.EncryptFile(openFileDialog1.FileName, txtPwd.Text, RefreshFileProgress);
                        DateTime t2 = DateTime.Now;
                        string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                        if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                        {
                            invokeDelegate = delegate()
                            {
                                EnableBtns();
                            };
                            InvokeUtil.Invoke(this, invokeDelegate);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK)
                        {
                            InvokeDelegate invokeDelegate = delegate()
                            {
                                EnableBtns();
                            };
                            InvokeUtil.Invoke(this, invokeDelegate);
                        }
                    }
                }));
                thread.Start();
            }
        }