CaptB 4 months ago
parent
commit
a6459ee7ea
14 changed files with 309 additions and 142 deletions
  1. 5 5
      App.config
  2. 1 1
      App.xaml
  3. 1 99
      App.xaml.cs
  4. 8 0
      ArchivesCenter3.csproj
  5. 23 0
      Login.xaml
  6. 76 0
      Login.xaml.cs
  7. 5 27
      MainWindow.xaml
  8. 43 0
      MainWindow.xaml.cs
  9. BIN
      Resources/icons8_omnichannel_64.png
  10. BIN
      Resources/omnichannel_96px.png
  11. 5 5
      Settings1.Designer.cs
  12. 5 5
      Settings1.settings
  13. 45 0
      reg.xaml
  14. 92 0
      reg.xaml.cs

+ 5 - 5
App.config

@@ -8,19 +8,19 @@
     <userSettings>
         <ArchivesCenter3.Settings1>
             <setting name="DatabaseName" serializeAs="String">
-                <value>DatabaseName</value>
+                <value />
             </setting>
             <setting name="DatabaseSubtitle" serializeAs="String">
-                <value>DatabaseSubtitle</value>
+                <value />
             </setting>
             <setting name="WelcomeTitle" serializeAs="String">
-                <value>WelcomeTitle</value>
+                <value />
             </setting>
             <setting name="Password" serializeAs="String">
-                <value>Password</value>
+                <value />
             </setting>
             <setting name="Username" serializeAs="String">
-                <value>Username</value>
+                <value />
             </setting>
             <setting name="IsOOBEPassed" serializeAs="String">
                 <value>False</value>

+ 1 - 1
App.xaml

@@ -2,7 +2,7 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:ArchivesCenter3"
-             StartupUri="MainWindow.xaml">
+             StartupUri="Login.xaml">
     <Application.Resources>
          
     </Application.Resources>

+ 1 - 99
App.xaml.cs

@@ -13,105 +13,7 @@ namespace ArchivesCenter3
     /// </summary>
     public partial class App : Application
     {
-        protected override void OnStartup(StartupEventArgs e)
-        {
-            base.OnStartup(e);
-            this.SessionEnding += App_SessionEnding;
-        }
-
-        private void App_SessionEnding(object sender, SessionEndingCancelEventArgs e)
-        {
-            try
-            {
-                // 获取用户文档库路径
-                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
-                string archivesCenterPath = Path.Combine(documentsPath, "ArchivesCenter");
-                string dataPath = Path.Combine(archivesCenterPath, "data");
-                string configPath = Path.Combine(archivesCenterPath, "config");
-                string backupPath = Path.Combine(archivesCenterPath, "backup");
-
-                // 确保备份文件夹存在
-                Directory.CreateDirectory(backupPath);
-
-                // 获取当前时间作为文件名
-                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
-                string backupFileName = Path.Combine(backupPath, $"backup_{timestamp}.zip");
-
-                // 获取加密密码
-                string password = Settings1.Default.Password;
-
-                // 创建压缩包并加密
-                using (FileStream zipToOpen = new FileStream(backupFileName, FileMode.Create))
-                {
-                    using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create, true))
-                    {
-                        // 添加 data 文件夹
-                        if (Directory.Exists(dataPath))
-                        {
-                            AddDirectoryToArchive(archive, dataPath, "data");
-                        }
-
-                        // 添加 config 文件夹
-                        if (Directory.Exists(configPath))
-                        {
-                            AddDirectoryToArchive(archive, configPath, "config");
-                        }
-                    }
-                }
-
-                // 加密压缩包
-                EncryptFile(backupFileName, backupFileName + ".enc", password);
-
-                // 删除未加密的压缩包
-                File.Delete(backupFileName);
-
-                MessageBox.Show("备份完成,文件已加密并保存到:\n" + backupFileName + ".enc");
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show("备份失败:" + ex.Message);
-            }
-        }
-
-        private void AddDirectoryToArchive(ZipArchive archive, string directoryPath, string entryName)
-        {
-            foreach (string file in Directory.GetFiles(directoryPath, "*.*", SearchOption.AllDirectories))
-            {
-                string entryFilePath = Path.GetRelativePath(directoryPath, file);
-                ZipArchiveEntry entry = archive.CreateEntry(Path.Combine(entryName, entryFilePath));
-                using (FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
-                {
-                    using (Stream entryStream = entry.Open())
-                    {
-                        fileStream.CopyTo(entryStream);
-                    }
-                }
-            }
-        }
-
-        private void EncryptFile(string inputFilePath, string outputFilePath, string password)
-        {
-            byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
-            using (Aes aesAlg = Aes.Create())
-            {
-                aesAlg.Key = passwordBytes;
-                aesAlg.IV = new byte[16]; // IV 长度必须为 16 字节
-
-                using (FileStream inputStream = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read))
-                {
-                    using (FileStream outputStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
-                    {
-                        using (ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV))
-                        {
-                            using (CryptoStream cryptoStream = new CryptoStream(outputStream, encryptor, CryptoStreamMode.Write))
-                            {
-                                inputStream.CopyTo(cryptoStream);
-                            }
-                        }
-                    }
-                }
-            }
-        }
+        
     }
 
 }

+ 8 - 0
ArchivesCenter3.csproj

@@ -16,16 +16,24 @@
     <None Remove="Resources\icons8_omnichannel.ico" />
     <None Remove="Resources\icons8_omnichannel_128.png" />
     <None Remove="Resources\icons8_omnichannel_48.png" />
+    <None Remove="Resources\icons8_omnichannel_64.png" />
+    <None Remove="Resources\omnichannel_96px.png" />
     <None Remove="Resources\refresh_16px.png" />
     <None Remove="SplashScreen1.png" />
   </ItemGroup>
 
+  <ItemGroup>
+    <PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />
+  </ItemGroup>
+
   <ItemGroup>
     <Resource Include="Resources\about_48px.png" />
     <Resource Include="Resources\database_administrator_48px.png" />
     <Resource Include="Resources\icons8_omnichannel.ico" />
     <Resource Include="Resources\icons8_omnichannel_128.png" />
     <Resource Include="Resources\icons8_omnichannel_48.png" />
+    <Resource Include="Resources\icons8_omnichannel_64.png" />
+    <Resource Include="Resources\omnichannel_96px.png" />
     <Resource Include="Resources\refresh_16px.png" />
   </ItemGroup>
 

+ 23 - 0
Login.xaml

@@ -0,0 +1,23 @@
+<Window x:Class="ArchivesCenter3.Login"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:ArchivesCenter3"
+        mc:Ignorable="d"
+        Title="数据库解密 - Archives Center" Height="300" Width="400" WindowStartupLocation="CenterScreen" Topmost="True" Icon="/Resources/icons8_omnichannel.ico">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="Auto"/>
+        </Grid.RowDefinitions>
+        <Image Source="/Resources/omnichannel_96px.png" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" Height="96"/>
+        <TextBlock Grid.Row="1" Text="Archives Center" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24" Foreground="#0368ba" Margin="10"/>
+        <TextBlock Grid.Row="2" Text="请输入数据库密钥" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+        <TextBox x:Name="LoginKeyBox" Grid.Row="3" HorizontalAlignment="Center" Margin="5" Width="150" Height="20"/>
+        <Button x:Name="LoginButton" Grid.Row="4" Width="60" Height="20" Margin="10" Click="Button_Click" IsEnabled="False">解密</Button>
+    </Grid>
+</Window>

+ 76 - 0
Login.xaml.cs

@@ -0,0 +1,76 @@
+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;
+        }
+    }
+}

+ 5 - 27
MainWindow.xaml

@@ -5,7 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:ArchivesCenter3"
         mc:Ignorable="d"
-        Title="Archives Center 主窗口" Height="450" Width="800" Icon="Resources/icons8_omnichannel.ico" ResizeMode="CanMinimize">
+        Title="Archives Center 主窗口" Height="450" Width="800" Icon="Resources/icons8_omnichannel.ico" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
     <Grid>
         <TabControl Background="#0368ba">
             <TabItem Header="开始">
@@ -25,6 +25,7 @@
                                     <RowDefinition Height="Auto" />
                                     <RowDefinition Height="20" />
                                     <RowDefinition Height="Auto" />
+                                    <RowDefinition Height="Auto" />
                                 </Grid.RowDefinitions>
                                 <Grid Grid.ColumnSpan="2" Grid.Row="0">
                                     <Grid.ColumnDefinitions>
@@ -43,30 +44,7 @@
                                 <TextBlock x:Name="DatabaseName" Grid.Column="1" Grid.Row="3" Text="dbName0" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="18" Foreground="#000000"/>
                                 <TextBlock x:Name="DatabaseSubtitle" Grid.Column="1" Grid.Row="4" Text="dbName1" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="18" Foreground="#989898"/>
                                 <TextBlock Grid.Column="1" Grid.Row="6" Text="此数据库中所收集之信息皆应由合法渠道取得。注意保密!" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="18" Foreground="#000000"/>
-                            </Grid>
-                        </TabItem>
-                        <TabItem Header="备份">
-                            <Grid>
-                                <Grid.ColumnDefinitions>
-                                    <ColumnDefinition Width="Auto"></ColumnDefinition>
-                                    <ColumnDefinition Width="Auto"></ColumnDefinition>
-                                    <ColumnDefinition Width="Auto"></ColumnDefinition>
-                                    <ColumnDefinition Width="*"></ColumnDefinition>
-                                </Grid.ColumnDefinitions>
-                                <Grid.RowDefinitions>
-                                    <RowDefinition Height="Auto"></RowDefinition>
-                                    <RowDefinition Height="*"></RowDefinition>
-                                </Grid.RowDefinitions>
-                                <Button Grid.Column="0" Grid.Row="0" Height="25" Width="75" Margin="10">创建还原点</Button>
-                                <Button Grid.Column="1" Grid.Row="0" Height="25" Width="75" Margin="10">还原</Button>
-                                <Button Grid.Column="2" Grid.Row="0" Height="25" Width="75" Margin="10">清除还原点</Button>
-                                <DataGrid Grid.ColumnSpan="4" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" IsReadOnly="True" Margin="10">
-                                    <DataGrid.Columns>
-                                        <DataGridTextColumn Header="创建时间" Width="Auto"/>
-                                        <DataGridTextColumn Header="占用空间" Width="Auto"/>
-                                        <DataGridTextColumn Header="占全部还原点占用空间百分比" Width="Auto"/>
-                                    </DataGrid.Columns>
-                                </DataGrid>
+                                <Button Grid.Column="1" Grid.Row="7" Margin="10" Height="20" Width="100" Click="Button_Click_2" HorizontalAlignment="Left">加密并退出</Button>
                             </Grid>
                         </TabItem>
                         <TabItem Header="设置">
@@ -90,7 +68,7 @@
                                         <RowDefinition Height="Auto" />
                                     </Grid.RowDefinitions>
                                     <Image Grid.Column="0" Grid.Row="0" Source="/Resources/database_administrator_48px.png" Margin="3"/>
-                                    <TextBlock Grid.Column="1" Grid.Row="0" Text="设置   " Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="24" Foreground="#0368ba"/>
+                                    <TextBlock Grid.Column="1" Grid.Row="0" Text="设置" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="24" Foreground="#0368ba"/>
                                     <Border Grid.ColumnSpan="3" Grid.Row="1" Background="#0368ba" Height="3"/>
                                 </Grid>
                                 <ScrollViewer Grid.ColumnSpan="3" Grid.Row="1">
@@ -98,7 +76,7 @@
                                         <Grid.ColumnDefinitions>
                                             <ColumnDefinition Width="Auto" />
                                             <ColumnDefinition Width="Auto" />
-                                            <ColumnDefinition Width="Auto" />
+                                            <ColumnDefinition Width="*" />
                                         </Grid.ColumnDefinitions>
                                         <Grid.RowDefinitions>
                                             <RowDefinition Height="Auto" />

+ 43 - 0
MainWindow.xaml.cs

@@ -1,10 +1,16 @@
 using System.IO;
 using System.Reflection;
+using System.Text;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
+using System.Windows.Input;
 using System.Windows.Media.Imaging;
 using Microsoft.Win32;
+using Org.BouncyCastle.Crypto.Engines;
+using Org.BouncyCastle.Crypto.Modes;
+using Org.BouncyCastle.Crypto.Paddings;
+using Org.BouncyCastle.Crypto.Parameters;
 
 namespace ArchivesCenter3
 {
@@ -756,6 +762,7 @@ namespace ArchivesCenter3
             {
                 // 删除文件夹及其内容
                 Directory.Delete(dateFolderPath, true);
+                MyRichTextBox.Document.Blocks.Clear();
 
                 MessageBox.Show("文件夹已删除!", "Archives Center", MessageBoxButton.OK, MessageBoxImage.Information);
             }
@@ -816,5 +823,41 @@ namespace ArchivesCenter3
                 MessageBox.Show($"搜索失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
+
+        private static byte[] key = Encoding.UTF8.GetBytes("8f4a3b5c6d7e9f1a2b3c4d5e6f7a8b9c");
+
+        private void Button_Click_2(object sender, RoutedEventArgs e)
+        {
+            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            string targetFolderPath = Path.Combine(documentsPath, "ArchivesCenter");
+            EncryptFolder(targetFolderPath);
+            this.Close();
+        }
+
+        public static void EncryptFolder(string folderPath)
+        {
+            foreach (string filePath in Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories))
+            {
+                byte[] fileContent = File.ReadAllBytes(filePath);
+                byte[] encryptedContent = Encrypt(fileContent);
+                File.WriteAllBytes(filePath, encryptedContent);
+                Console.WriteLine($"Encrypted: {filePath}");
+            }
+        }
+
+        private static readonly byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
+
+        private static byte[] Encrypt(byte[] plaintext)
+        {
+            var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new AesEngine()), new Pkcs7Padding());
+            var keyParam = new KeyParameter(key);
+            var parameters = new ParametersWithIV(keyParam, iv);
+            cipher.Init(true, parameters);
+
+            byte[] output = new byte[cipher.GetOutputSize(plaintext.Length)];
+            int length = cipher.ProcessBytes(plaintext, 0, plaintext.Length, output, 0);
+            cipher.DoFinal(output, length);
+            return output;
+        }
     }
 }

BIN
Resources/icons8_omnichannel_64.png


BIN
Resources/omnichannel_96px.png


+ 5 - 5
Settings1.Designer.cs

@@ -25,7 +25,7 @@ namespace ArchivesCenter3 {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("DatabaseName")]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
         public string DatabaseName {
             get {
                 return ((string)(this["DatabaseName"]));
@@ -37,7 +37,7 @@ namespace ArchivesCenter3 {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("DatabaseSubtitle")]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
         public string DatabaseSubtitle {
             get {
                 return ((string)(this["DatabaseSubtitle"]));
@@ -49,7 +49,7 @@ namespace ArchivesCenter3 {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("WelcomeTitle")]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
         public string WelcomeTitle {
             get {
                 return ((string)(this["WelcomeTitle"]));
@@ -61,7 +61,7 @@ namespace ArchivesCenter3 {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Password")]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
         public string Password {
             get {
                 return ((string)(this["Password"]));
@@ -73,7 +73,7 @@ namespace ArchivesCenter3 {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Username")]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
         public string Username {
             get {
                 return ((string)(this["Username"]));

+ 5 - 5
Settings1.settings

@@ -3,19 +3,19 @@
   <Profiles />
   <Settings>
     <Setting Name="DatabaseName" Type="System.String" Scope="User">
-      <Value Profile="(Default)">DatabaseName</Value>
+      <Value Profile="(Default)" />
     </Setting>
     <Setting Name="DatabaseSubtitle" Type="System.String" Scope="User">
-      <Value Profile="(Default)">DatabaseSubtitle</Value>
+      <Value Profile="(Default)" />
     </Setting>
     <Setting Name="WelcomeTitle" Type="System.String" Scope="User">
-      <Value Profile="(Default)">WelcomeTitle</Value>
+      <Value Profile="(Default)" />
     </Setting>
     <Setting Name="Password" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Password</Value>
+      <Value Profile="(Default)" />
     </Setting>
     <Setting Name="Username" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Username</Value>
+      <Value Profile="(Default)" />
     </Setting>
     <Setting Name="IsOOBEPassed" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">False</Value>

+ 45 - 0
reg.xaml

@@ -0,0 +1,45 @@
+<Window x:Class="ArchivesCenter3.reg"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:ArchivesCenter3"
+        mc:Ignorable="d"
+        Title="OOBE - Archives Center" Height="300" Width="400" WindowStartupLocation="CenterScreen" Topmost="True" Icon="/Resources/icons8_omnichannel.ico">
+    <Grid>
+        <ScrollViewer>
+            <Grid>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                </Grid.RowDefinitions>
+                <Image Source="/Resources/omnichannel_96px.png" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" Height="96"/>
+                <TextBlock Grid.Row="1" Text="Archives Center" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24" Foreground="#0368ba" Margin="5"/>
+                <TextBlock Grid.Row="2" Text="开箱体验" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24" Foreground="#0368ba" Margin="5"/>
+                <TextBlock x:Name="regdbN" Grid.Row="3" Text="数据库标题" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+                <TextBox Grid.Row="4" HorizontalAlignment="Center" Margin="5" Width="150" Height="20"/>
+                <TextBlock x:Name="regdbsN" Grid.Row="5" Text="数据库副标题" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+                <TextBox Grid.Row="6" HorizontalAlignment="Center" Margin="5" Width="150" Height="20"/>
+                <TextBlock x:Name="regWT" Grid.Row="7" Text="欢迎标题" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+                <TextBox Grid.Row="8" HorizontalAlignment="Center" Margin="5" Width="150" Height="20"/>
+                <TextBlock x:Name="regUN" Grid.Row="9" Text="用户名" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+                <TextBox Grid.Row="10" HorizontalAlignment="Center" Margin="5" Width="150" Height="20"/>
+                <TextBlock Grid.Row="11" Text="★数据库密钥" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5"/>
+                <TextBox x:Name="regbox" Grid.Row="12" HorizontalAlignment="Center" Margin="5" Width="150" Height="20" TextChanged="TextBox_TextChanged"/>
+                <Button x:Name="regbutton" Grid.Row="13" Width="60" Height="20" Margin="10" IsEnabled="False" Click="regbutton_Click">完成</Button>
+            </Grid>
+        </ScrollViewer>
+    </Grid>
+</Window>

+ 92 - 0
reg.xaml.cs

@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+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>
+    /// reg.xaml 的交互逻辑
+    /// </summary>
+    public partial class reg : Window
+    {
+        public reg()
+        {
+            InitializeComponent();
+        }
+
+        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (regbox.Text.Length > 0)
+                regbutton.IsEnabled = true;
+            else
+                regbutton.IsEnabled = false;
+        }
+
+        private void regbutton_Click(object sender, RoutedEventArgs e)
+        {
+            Settings1.Default.DatabaseName = regdbN.Text;
+            Settings1.Default.DatabaseSubtitle = regdbsN.Text;
+            Settings1.Default.WelcomeTitle = regWT.Text;
+            Settings1.Default.Password = regbox.Text;
+            Settings1.Default.Username = regUN.Text;
+            Settings1.Default.IsOOBEPassed = true;
+            Settings1.Default.Save();
+            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+
+            // 构造目标文件夹路径
+            string targetFolderPath = Path.Combine(documentsPath, "ArchivesCenter");
+            if (!Directory.Exists(targetFolderPath))
+            {
+                Directory.CreateDirectory(targetFolderPath);
+            }
+            EncryptFolder(targetFolderPath);
+            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 EncryptFolder(string folderPath)
+        {
+            foreach (string filePath in Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories))
+            {
+                byte[] fileContent = File.ReadAllBytes(filePath);
+                byte[] encryptedContent = Encrypt(fileContent);
+                File.WriteAllBytes(filePath, encryptedContent);
+                Console.WriteLine($"Encrypted: {filePath}");
+            }
+        }
+
+        private static byte[] Encrypt(byte[] plaintext)
+        {
+            var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new AesEngine()), new Pkcs7Padding());
+            var keyParam = new KeyParameter(key);
+            var parameters = new ParametersWithIV(keyParam, iv);
+            cipher.Init(true, parameters);
+
+            byte[] output = new byte[cipher.GetOutputSize(plaintext.Length)];
+            int length = cipher.ProcessBytes(plaintext, 0, plaintext.Length, output, 0);
+            cipher.DoFinal(output, length);
+            return output;
+        }
+    }
+}