MainForm.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 md5 = fct.GetMD5(file);
  35. string newfile = file + ".fmk";
  36. if (!File.Exists(newfile))
  37. {
  38. if (FileEncryptTool.Encrypt(file, newfile, pwd))
  39. {
  40. MessageBox.Show("恭喜你,加密成功。", "加密成功");
  41. }
  42. }
  43. else
  44. {
  45. MessageBox.Show("您选择的文件已存在加密文件", "??");
  46. }
  47. }
  48. }
  49. }
  50. private void BtFileDecrypt_Click(object sender, EventArgs e)
  51. {
  52. string pwd = "12345678901234567890123456789012";
  53. string[] fileInfo = new string[128];
  54. OpenFileDialog fileDialog = new OpenFileDialog();
  55. fileDialog.Title = "请选择要解密的文件";
  56. fileDialog.Filter = "加密文件|*.fmk";
  57. if (fileDialog.ShowDialog() == DialogResult.OK)
  58. {
  59. string file = fileDialog.FileName;
  60. if (File.Exists(file))
  61. {
  62. string newfile = file.Substring(0, file.Length - ".fmk".Length);
  63. if (!File.Exists(newfile))
  64. {
  65. if (FileEncryptTool.Decrypt(file, newfile, pwd))
  66. {
  67. MessageBox.Show("恭喜你,解密成功。", "解密成功");
  68. }
  69. }
  70. else
  71. {
  72. MessageBox.Show("您选择的文件已存在解密文件", "??");
  73. }
  74. }
  75. }
  76. }
  77. private void MainForm_Load(object sender, EventArgs e)
  78. {
  79. }
  80. }
  81. }