MainForm.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Y.Utils.DataUtils.EncryptUtils;
  12. using Y.Utils.IOUtils.FileUtils;
  13. using Y.Utils.IOUtils.PathUtils;
  14. namespace Oreo.FileMan.Views
  15. {
  16. public partial class MainForm : Form
  17. {
  18. FileCodeTool fct = new FileCodeTool();
  19. public MainForm()
  20. {
  21. InitializeComponent();
  22. }
  23. private void BtFileEncrypt_Click(object sender, EventArgs e)
  24. {
  25. string pwd = "123456789012";
  26. OpenFileDialog fileDialog = new OpenFileDialog();
  27. fileDialog.Title = "请选择要加密的文件";
  28. fileDialog.Filter = "所有文件|*.*";
  29. if (fileDialog.ShowDialog() == DialogResult.OK)
  30. {
  31. string file = fileDialog.FileName;
  32. if (File.Exists(file))
  33. {
  34. string newfile = file + ".fmk";
  35. if (!File.Exists(newfile))
  36. {
  37. if (FileEncryptTool.Encrypt(file, newfile, pwd) > 0)
  38. {
  39. MessageBox.Show("恭喜你,加密成功。", "加密成功");
  40. }
  41. }
  42. else
  43. {
  44. MessageBox.Show("您选择的文件已存在加密文件", "??");
  45. }
  46. }
  47. }
  48. }
  49. private void BtFileDecrypt_Click(object sender, EventArgs e)
  50. {
  51. string pwd = "1234567890121";
  52. string[] fileInfo = new string[128];
  53. OpenFileDialog fileDialog = new OpenFileDialog();
  54. fileDialog.Title = "请选择要解密的文件";
  55. fileDialog.Filter = "加密文件|*.fmk";
  56. if (fileDialog.ShowDialog() == DialogResult.OK)
  57. {
  58. string file = fileDialog.FileName;
  59. if (File.Exists(file))
  60. {
  61. string newfile = file.Substring(0, file.Length - ".fmk".Length);
  62. if (!File.Exists(newfile))
  63. {
  64. if (FileEncryptTool.Decrypt(file, newfile, pwd) > 0)
  65. {
  66. MessageBox.Show("恭喜你,解密成功。", "解密成功");
  67. }
  68. }
  69. else
  70. {
  71. MessageBox.Show("您选择的文件已存在解密文件", "??");
  72. }
  73. }
  74. }
  75. }
  76. private void MainForm_Load(object sender, EventArgs e)
  77. {
  78. }
  79. }
  80. }