Bläddra i källkod

增加密码解锁

样式分支
fyf 2 år sedan
förälder
incheckning
1f4f46061e
5 ändrade filer med 166 tillägg och 4 borttagningar
  1. +46
    -0
      BPASmartClient.CustomResource/Themes/GenricStyle.xaml
  2. +80
    -0
      BPASmartClient.Helper/AESHelper.cs
  3. +3
    -2
      BPASmartClient/App.config
  4. +11
    -1
      BPASmartClient/Control/DataVView.xaml
  5. +26
    -1
      BPASmartClient/Control/DataVView.xaml.cs

+ 46
- 0
BPASmartClient.CustomResource/Themes/GenricStyle.xaml Visa fil

@@ -123,6 +123,52 @@
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<Style TargetType="{x:Type PasswordBox}">
<Setter Property="PasswordChar" Value="●"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="#FF02C9FD"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="CaretBrush" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Border x:Name="border" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" BorderBrush="#FF08335F">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ExpanderUpHeaderStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>


+ 80
- 0
BPASmartClient.Helper/AESHelper.cs Visa fil

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Helper
{
/// <summary>
/// 创建AES加密解密 add fyf 20211122
/// </summary>
public class AESHelper
{
/// <summary>
/// 默认密钥-密钥的长度必须是32
/// </summary>
private const string PublicKey = "9848461354184618";
/// <summary>
/// 默认向量
/// </summary>
private const string Iv = "dfkladnasldnfdcv";
/// <summary>
/// AES加密
/// </summary>
/// <param name="str">需要加密字符串</param>
/// <returns>加密后字符串</returns>
public static String Encrypt(string str)
{
return Encrypt(str, PublicKey);
}
/// <summary>
/// AES解密
/// </summary>
/// <param name="str">需要解密字符串</param>
/// <returns>解密后字符串</returns>
public static String Decrypt(string str)
{
return Decrypt(str, PublicKey);
}
/// <summary>
/// AES加密
/// </summary>
/// <param name="str">需要加密的字符串</param>
/// <param name="key">32位密钥</param>
/// <returns>加密后的字符串</returns>
public static string Encrypt(string str, string key)
{
Byte[] keyArray = System.Text.Encoding.UTF8.GetBytes(key);
Byte[] toEncryptArray = System.Text.Encoding.UTF8.GetBytes(str);
var rijndael = new System.Security.Cryptography.RijndaelManaged();
rijndael.Key = keyArray;
rijndael.Mode = System.Security.Cryptography.CipherMode.ECB;
rijndael.Padding = System.Security.Cryptography.PaddingMode.PKCS7;
rijndael.IV = System.Text.Encoding.UTF8.GetBytes(Iv);
System.Security.Cryptography.ICryptoTransform cTransform = rijndael.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
/// <summary>
/// AES解密
/// </summary>
/// <param name="str">需要解密的字符串</param>
/// <param name="key">32位密钥</param>
/// <returns>解密后的字符串</returns>
public static string Decrypt(string str, string key)
{
Byte[] keyArray = System.Text.Encoding.UTF8.GetBytes(key);
Byte[] toEncryptArray = Convert.FromBase64String(str);
var rijndael = new System.Security.Cryptography.RijndaelManaged();
rijndael.Key = keyArray;
rijndael.Mode = System.Security.Cryptography.CipherMode.ECB;
rijndael.Padding = System.Security.Cryptography.PaddingMode.PKCS7;
rijndael.IV = System.Text.Encoding.UTF8.GetBytes(Iv);
System.Security.Cryptography.ICryptoTransform cTransform = rijndael.CreateDecryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return System.Text.Encoding.UTF8.GetString(resultArray);
}

}
}

+ 3
- 2
BPASmartClient/App.config Visa fil

@@ -3,7 +3,7 @@
<appSettings>
<!--通用配置-->
<!--1:且时且多冰淇淋咖啡机,2:且时且多煮面机,3:海科煮面机测试店铺-->
<add key="ClientId" value="46"/>
<add key="ClientId" value="46232"/>
<!--<add key="ApolloUri" value="http://10.2.1.21:28080"/>
<add key="OrderServiceUri" value="http://10.2.1.26:21527/order/"/>
<add key="StockServiceUri" value="http://10.2.1.26:21527/stock/"/>-->
@@ -47,9 +47,10 @@
<add key="ProductKey" value="grgpECHSL7q"/>
<add key="DeviceName" value="qsqd"/>
<add key="DeviceSecret" value="3c0f2390943bff4fece523af22655196"/>
<add key="PasswordBox" value="6WrKhYmTIhLV7g24jIH/lg=="/>


<!--外设配置-->
<!--外设配置-->
<add key="COM_Coffee" value="COM3"/>
<add key="BAUD_Coffee" value="115200"/>
<add key="COM_IceCream" value="COM12"/>


+ 11
- 1
BPASmartClient/Control/DataVView.xaml Visa fil

@@ -16,9 +16,11 @@
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="0.8*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="10">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Width="80" FontSize="12">API查询地址:</TextBlock>
@@ -149,5 +151,13 @@
</DataGrid>

</Grid>

<Grid x:Name="Pass" Grid.ColumnSpan="2" Background="#99020202">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Width="80" FontSize="16" Margin="0,0,0,5">密码解锁:</TextBlock>
<PasswordBox x:Name="passbox" Width="180" Height="22" ></PasswordBox>
<Button HorizontalAlignment="Right" Margin="0,5,0,0" Tag="OkPass" Click="Button_Click" Style="{DynamicResource CommonBtn_返回}" Width="45" IsDefault="True">确定</Button>
</StackPanel>
</Grid>
</Grid>
</UserControl>

+ 26
- 1
BPASmartClient/Control/DataVView.xaml.cs Visa fil

@@ -1,5 +1,6 @@
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.Helper;
using BPASmartClient.IoT;
using BPASmartClient.ViewModel;
using DataVAPI.Tool.IOT;
@@ -18,6 +19,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BPASmartClient.Control
{
@@ -26,10 +28,24 @@ namespace BPASmartClient.Control
/// </summary>
public partial class DataVView : UserControl
{
string OnPass=string.Empty;
public DispatcherTimer dispatcherTimer;
public DataVView()
{
InitializeComponent();
OnPass = AESHelper.Decrypt(System.Configuration.ConfigurationManager.AppSettings["PasswordBox"].ToString());
this.DataContext = DataVViewModel.GetInstance();
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += delegate
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
Pass.Visibility = Visibility.Visible;
dispatcherTimer.Stop();
}));
};
dispatcherTimer.Interval = TimeSpan.FromSeconds(20);
}

private void Button_Click(object sender, RoutedEventArgs e)
@@ -107,7 +123,16 @@ namespace BPASmartClient.Control
DataVViewModel.GetInstance().Refresh();
}
}

break;
case "OkPass":
if (passbox.Password == OnPass)
{
Pass.Visibility = Visibility.Collapsed;
passbox.Password = "";
dispatcherTimer.Start();
}
else
NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, MainViewModel.GetInstance().window, "提示", $"密码输入错误!");
break;
}
}


Laddar…
Avbryt
Spara