From b400726efc55b021f8436918bdfee0976eac4cd3 Mon Sep 17 00:00:00 2001 From: Shiroiame-Kusu Date: Thu, 8 Aug 2024 15:44:30 +0800 Subject: [PATCH] Still this Version: Added Some Small Features. --- LoCyanFrpDesktop/Dashboard/Settings.xaml | 14 +++--- LoCyanFrpDesktop/Dashboard/Settings.xaml.cs | 49 +++++++++++---------- LoCyanFrpDesktop/Utils/RSAEncryption.cs | 44 ++++++++++++++++++ 3 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 LoCyanFrpDesktop/Utils/RSAEncryption.cs diff --git a/LoCyanFrpDesktop/Dashboard/Settings.xaml b/LoCyanFrpDesktop/Dashboard/Settings.xaml index 2f01eff..92d5354 100644 --- a/LoCyanFrpDesktop/Dashboard/Settings.xaml +++ b/LoCyanFrpDesktop/Dashboard/Settings.xaml @@ -48,16 +48,20 @@ Content="选择文件" Icon="OpenFolder24"/> - + - - + + - - + + + + + + diff --git a/LoCyanFrpDesktop/Dashboard/Settings.xaml.cs b/LoCyanFrpDesktop/Dashboard/Settings.xaml.cs index 3ad4b1a..09716a7 100644 --- a/LoCyanFrpDesktop/Dashboard/Settings.xaml.cs +++ b/LoCyanFrpDesktop/Dashboard/Settings.xaml.cs @@ -26,18 +26,19 @@ namespace LoCyanFrpDesktop.Dashboard /// public partial class Settings : UiPage { - private static int i = 0; + public Settings() { InitializeComponent(); Access.Settings = this; - _Version.Text = $"版本: Ver {Global.Version}-{Global.Branch}{Global.Revision}"; + _Version.Text = $"版本: Ver {Global.Version}-{Global.Branch}{((Global.Branch == "Alpha" || Global.Branch == "Beta") ? "." : "")}{Global.Revision}"; _BuildInfo.Text = Global.BuildInfo.ToString(); _Developer.Text = $"开发者: {Global.Developer}"; _Copyright.Text = Global.Copyright; FrpcPath.Text = Global.Config.FrpcPath; AppliedTheme.SelectedIndex = Global.Config.AppliedTheme; + AppliedTheme.SelectionChanged += AppliedTheme_SelectionChanged; } public void Select_Click(object sender, RoutedEventArgs e) { @@ -75,31 +76,33 @@ private void SignOut_Click(object sender, RoutedEventArgs e) private void AppliedTheme_SelectionChanged(object sender, SelectionChangedEventArgs e) { - - if(i > 0) + Global.Config.AppliedTheme = AppliedTheme.SelectedIndex; + switch (AppliedTheme.SelectedIndex) { - Global.Config.AppliedTheme = AppliedTheme.SelectedIndex; - switch (AppliedTheme.SelectedIndex) - { - case 0: - MainWindow.IsDarkThemeEnabled(); + case 0: + MainWindow.IsDarkThemeEnabled(); - break; - case 1: - Global.isDarkThemeEnabled = true; - Theme.Apply(ThemeType.Dark); - break; - case 2: - Global.isDarkThemeEnabled = false; - Theme.Apply(ThemeType.Light); - break; - default: - throw new IndexOutOfRangeException(); + break; + case 1: + Global.isDarkThemeEnabled = true; + Theme.Apply(ThemeType.Dark); + break; + case 2: + Global.isDarkThemeEnabled = false; + Theme.Apply(ThemeType.Light); + break; + default: + throw new IndexOutOfRangeException(); - } - Access.DashBoard.ChangeColor(); } - i++; + Access.DashBoard.ChangeColor(); + + } + + private void CopyToken_Click(object sender, RoutedEventArgs e) + { + Clipboard.SetText(Global.Config.FrpToken); + Logger.MsgBox("LocyanFrpDesktop\n已经复制啦~", "LocyanFrpDesktop", 0, 47, 1); } } } diff --git a/LoCyanFrpDesktop/Utils/RSAEncryption.cs b/LoCyanFrpDesktop/Utils/RSAEncryption.cs new file mode 100644 index 0000000..df31438 --- /dev/null +++ b/LoCyanFrpDesktop/Utils/RSAEncryption.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace LoCyanFrpDesktop.Utils +{ + internal class RSAEncryption + { + public RSAEncryption() { + string publicKey, privateKey; + using (var rsa = new RSACryptoServiceProvider(4096)) + { + publicKey = rsa.ToXmlString(false); // Public key + privateKey = rsa.ToXmlString(true); // Private key + } + + } + public static byte[] EncryptData(string dataToEncrypt, string publicKey) + { + byte[] encryptedData; + using (var rsa = new RSACryptoServiceProvider(4096)) + { + rsa.FromXmlString(publicKey); + var dataToEncryptBytes = Encoding.UTF8.GetBytes(dataToEncrypt); + encryptedData = rsa.Encrypt(dataToEncryptBytes, false); + } + return encryptedData; + } + + public static string DecryptData(byte[] dataToDecrypt, string privateKey) + { + byte[] decryptedData; + using (var rsa = new RSACryptoServiceProvider(4096)) + { + rsa.FromXmlString(privateKey); + decryptedData = rsa.Decrypt(dataToDecrypt, false); + } + return Encoding.UTF8.GetString(decryptedData); + } + } +}