12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.IO;
- using System.Text;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Shapes;
- using Org.BouncyCastle.Crypto.Engines;
- using Org.BouncyCastle.Crypto.Modes;
- using Org.BouncyCastle.Crypto.Paddings;
- using Org.BouncyCastle.Crypto.Parameters;
- using Path = System.IO.Path;
- namespace ArchivesCenter3
- {
- /// <summary>
- /// Login.xaml 的交互逻辑
- /// </summary>
- public partial class Login : Window
- {
- public Login()
- {
- InitializeComponent();
- Settings1.Default.IsOOBEPassed = false;
- Settings1.Default.Save();
- if (Settings1.Default.IsOOBEPassed)
- LoginButton.IsEnabled = true;
- else
- {
- reg reg = new reg();
- reg.ShowDialog();
- LoginButton.IsEnabled = true;
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- string targetFolderPath = Path.Combine(documentsPath, "ArchivesCenter");
- if (LoginKeyBox.Text == Settings1.Default.Password)
- {
- DecryptFolder(targetFolderPath);
- MainWindow mainWindow = new MainWindow();
- mainWindow.Show();
- this.Close();
- }
- }
- private static byte[] key = Encoding.UTF8.GetBytes("8f4a3b5c6d7e9f1a2b3c4d5e6f7a8b9c");
- // 定义一个固定的初始化向量(IV),长度为 16 字节
- private static readonly byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
- public static void DecryptFolder(string folderPath)
- {
- foreach (string filePath in Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories))
- {
- byte[] encryptedContent = File.ReadAllBytes(filePath);
- byte[] decryptedContent = Decrypt(encryptedContent);
- File.WriteAllBytes(filePath, decryptedContent);
- Console.WriteLine($"Decrypted: {filePath}");
- }
- }
- private static byte[] Decrypt(byte[] ciphertext)
- {
- var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new AesEngine()), new Pkcs7Padding());
- var keyParam = new KeyParameter(key);
- var parameters = new ParametersWithIV(keyParam, iv);
- cipher.Init(false, parameters);
- byte[] output = new byte[cipher.GetOutputSize(ciphertext.Length)];
- int length = cipher.ProcessBytes(ciphertext, 0, ciphertext.Length, output, 0);
- cipher.DoFinal(output, length);
- return output;
- }
- }
- }
|