添加机器码校验,删除加密狗
This commit is contained in:
6
ACP.sln
6
ACP.sln
@@ -37,8 +37,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceEditModule", "DeviceE
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CANModule", "CANModule\CANModule.csproj", "{AF2533DD-599D-49D7-942B-B0C26534D15F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CANModule", "CANModule\CANModule.csproj", "{AF2533DD-599D-49D7-942B-B0C26534D15F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "加密狗", "加密狗\加密狗.csproj", "{A35CA316-7B5B-4183-8636-4ECA532B1489}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CurveModule", "CurveModule\CurveModule.csproj", "{84006890-9288-44C4-9D17-FA88F3FDECFA}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CurveModule", "CurveModule\CurveModule.csproj", "{84006890-9288-44C4-9D17-FA88F3FDECFA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExportModule", "ExportModule\ExportModule.csproj", "{8923122F-F7D3-4AE7-9E86-9E78F1296A11}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExportModule", "ExportModule\ExportModule.csproj", "{8923122F-F7D3-4AE7-9E86-9E78F1296A11}"
|
||||||
@@ -117,10 +115,6 @@ Global
|
|||||||
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{AF2533DD-599D-49D7-942B-B0C26534D15F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{A35CA316-7B5B-4183-8636-4ECA532B1489}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A35CA316-7B5B-4183-8636-4ECA532B1489}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A35CA316-7B5B-4183-8636-4ECA532B1489}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A35CA316-7B5B-4183-8636-4ECA532B1489}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
<ProjectReference Include="..\TSMasterCAN\TSMasterCAN.csproj" />
|
<ProjectReference Include="..\TSMasterCAN\TSMasterCAN.csproj" />
|
||||||
<ProjectReference Include="..\UIShare\UIShare.csproj" />
|
<ProjectReference Include="..\UIShare\UIShare.csproj" />
|
||||||
<ProjectReference Include="..\UpdateInfoMoudle\UpdateInfoMoudle.csproj" />
|
<ProjectReference Include="..\UpdateInfoMoudle\UpdateInfoMoudle.csproj" />
|
||||||
<ProjectReference Include="..\加密狗\加密狗.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ using DeviceCommand.Base;
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using ACP.Profiles;
|
using ACP.Profiles;
|
||||||
using 加密狗;
|
using UIShare.Helpers;
|
||||||
|
|
||||||
namespace ACP
|
namespace ACP
|
||||||
{
|
{
|
||||||
@@ -83,44 +83,17 @@ namespace ACP
|
|||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
string myMachineCode = MachineCodeHelper.GetDeviceMachineCode();
|
||||||
string strUserSn = "ACA89B2C1194650D4E93D97BE189FFCC";
|
if (MachineCodeHelper.VerifyMachineCode(myMachineCode))
|
||||||
string strApiKey = "C6D01BCD442347822876F8232245DE9422643C167B8C61CE4DF6049990E7395588675A8FC6AA4BF7AD353D669C993236BEA83F77551753885A47AF34185CC3A7";
|
|
||||||
|
|
||||||
Byte[] buffer = new Byte[256];
|
|
||||||
buffer = System.Text.Encoding.Default.GetBytes(strUserSn);
|
|
||||||
uint retcode;
|
|
||||||
retcode = 加密狗驱动类.验证加密狗SN(buffer);
|
|
||||||
if (retcode != 0)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show(string.Format("设置UserSN失败 error code: 0x{0:x}", retcode));
|
base.OnStartup(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("机器码不匹配!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint count = 0;
|
|
||||||
retcode = 加密狗API类.VikeyFind(ref count);
|
|
||||||
if (retcode != 0 || count == 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show("未找到加密狗");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer = System.Text.Encoding.Default.GetBytes(strApiKey);
|
|
||||||
retcode = 加密狗驱动类.验证加密狗APIkey(0, buffer);
|
|
||||||
if (retcode != 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show(string.Format("设置api密钥失败 error code: 0x{0:x}", retcode));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var remaining = 加密狗驱动类.检查剩余时间(0);
|
|
||||||
if (remaining <= TimeSpan.Zero)
|
|
||||||
{
|
|
||||||
MessageBox.Show("加密狗已到期或未能读取时间,请联系供应商。", "加密狗验证失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnStartup(e);
|
|
||||||
}
|
}
|
||||||
protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
|
protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
|
||||||
{
|
{
|
||||||
|
|||||||
102
UIShare/Tools/MachineCodeHelper.cs
Normal file
102
UIShare/Tools/MachineCodeHelper.cs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.Management;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace UIShare.Helpers
|
||||||
|
{
|
||||||
|
public static class MachineCodeHelper
|
||||||
|
{
|
||||||
|
private static string UniqueCode = "2021E5B9BB0A54685B9445873F01D8F7";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 校验机器码
|
||||||
|
/// </summary>
|
||||||
|
public static bool VerifyMachineCode(string MachineCode)
|
||||||
|
{
|
||||||
|
return UniqueCode == MachineCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取最终的设备唯一机器码
|
||||||
|
/// </summary>
|
||||||
|
public static string GetDeviceMachineCode()
|
||||||
|
{
|
||||||
|
string cpuId = GetCpuId();
|
||||||
|
string boardId = GetMotherboardId();
|
||||||
|
|
||||||
|
// 将主板和CPU序列号拼接,并转换为MD5,生成一个干净的、固定长度的机器码
|
||||||
|
string rawCode = $"CPU:{cpuId}_BOARD:{boardId}";
|
||||||
|
return GetMD5Hash(rawCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 CPU 序列号
|
||||||
|
/// </summary>
|
||||||
|
private static string GetCpuId()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (ManagementClass mc = new ManagementClass("win32_processor"))
|
||||||
|
{
|
||||||
|
using (ManagementObjectCollection moc = mc.GetInstances())
|
||||||
|
{
|
||||||
|
foreach (ManagementObject mo in moc)
|
||||||
|
{
|
||||||
|
return mo.Properties["ProcessorId"].Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 如果获取失败,返回一个默认标识
|
||||||
|
}
|
||||||
|
return "UNKNOWN_CPU";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取主板序列号 (最稳定的硬件标识)
|
||||||
|
/// </summary>
|
||||||
|
private static string GetMotherboardId()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (ManagementClass mc = new ManagementClass("Win32_BaseBoard"))
|
||||||
|
{
|
||||||
|
using (ManagementObjectCollection moc = mc.GetInstances())
|
||||||
|
{
|
||||||
|
foreach (ManagementObject mo in moc)
|
||||||
|
{
|
||||||
|
return mo.Properties["SerialNumber"].Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return "UNKNOWN_BOARD";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字符串 MD5 加密
|
||||||
|
/// </summary>
|
||||||
|
private static string GetMD5Hash(string input)
|
||||||
|
{
|
||||||
|
using (MD5 md5 = MD5.Create())
|
||||||
|
{
|
||||||
|
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
|
||||||
|
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||||
|
|
||||||
|
// 将字节数组转换为16进制字符串
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < hashBytes.Length; i++)
|
||||||
|
{
|
||||||
|
sb.Append(hashBytes[i].ToString("X2"));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
|
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
|
||||||
<PackageReference Include="Notifications.Wpf.Core" Version="2.0.1" />
|
<PackageReference Include="Notifications.Wpf.Core" Version="2.0.1" />
|
||||||
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
|
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
|
||||||
|
<PackageReference Include="System.Management" Version="11.0.0-preview.6.26359.118" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Common\Common.csproj" />
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
|
|||||||
Reference in New Issue
Block a user