From 156a04817ceafedec5e5f96b5049f4b072149508 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Chsc=E2=80=9D?= <“huangsucan@kaiyili-lab.com”>
Date: Thu, 30 Jul 2026 14:06:33 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=BA=E5=99=A8=E7=A0=81?=
=?UTF-8?q?=E6=A0=A1=E9=AA=8C=EF=BC=8C=E5=88=A0=E9=99=A4=E5=8A=A0=E5=AF=86?=
=?UTF-8?q?=E7=8B=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ACP.sln | 6 --
ACP/ACP.csproj | 1 -
ACP/App.xaml.cs | 45 +++----------
UIShare/Tools/MachineCodeHelper.cs | 102 +++++++++++++++++++++++++++++
UIShare/UIShare.csproj | 1 +
5 files changed, 112 insertions(+), 43 deletions(-)
create mode 100644 UIShare/Tools/MachineCodeHelper.cs
diff --git a/ACP.sln b/ACP.sln
index 1808d71..34931f0 100644
--- a/ACP.sln
+++ b/ACP.sln
@@ -37,8 +37,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceEditModule", "DeviceE
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CANModule", "CANModule\CANModule.csproj", "{AF2533DD-599D-49D7-942B-B0C26534D15F}"
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}"
EndProject
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}.Release|Any CPU.ActiveCfg = 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.Build.0 = Debug|Any CPU
{84006890-9288-44C4-9D17-FA88F3FDECFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/ACP/ACP.csproj b/ACP/ACP.csproj
index 37b3348..f159891 100644
--- a/ACP/ACP.csproj
+++ b/ACP/ACP.csproj
@@ -34,7 +34,6 @@
-
diff --git a/ACP/App.xaml.cs b/ACP/App.xaml.cs
index fa86616..7541911 100644
--- a/ACP/App.xaml.cs
+++ b/ACP/App.xaml.cs
@@ -23,7 +23,7 @@ using DeviceCommand.Base;
using AutoMapper;
using Microsoft.Extensions.Logging.Abstractions;
using ACP.Profiles;
-using 加密狗;
+using UIShare.Helpers;
namespace ACP
{
@@ -83,44 +83,17 @@ namespace ACP
base.OnStartup(e);
return;
}
-
- string strUserSn = "ACA89B2C1194650D4E93D97BE189FFCC";
- string strApiKey = "C6D01BCD442347822876F8232245DE9422643C167B8C61CE4DF6049990E7395588675A8FC6AA4BF7AD353D669C993236BEA83F77551753885A47AF34185CC3A7";
-
- Byte[] buffer = new Byte[256];
- buffer = System.Text.Encoding.Default.GetBytes(strUserSn);
- uint retcode;
- retcode = 加密狗驱动类.验证加密狗SN(buffer);
- if (retcode != 0)
+ string myMachineCode = MachineCodeHelper.GetDeviceMachineCode();
+ if (MachineCodeHelper.VerifyMachineCode(myMachineCode))
{
- MessageBox.Show(string.Format("设置UserSN失败 error code: 0x{0:x}", retcode));
+ base.OnStartup(e);
+ }
+ else
+ {
+ MessageBox.Show("机器码不匹配!");
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)
{
diff --git a/UIShare/Tools/MachineCodeHelper.cs b/UIShare/Tools/MachineCodeHelper.cs
new file mode 100644
index 0000000..b166ac1
--- /dev/null
+++ b/UIShare/Tools/MachineCodeHelper.cs
@@ -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";
+
+ ///
+ /// 校验机器码
+ ///
+ public static bool VerifyMachineCode(string MachineCode)
+ {
+ return UniqueCode == MachineCode;
+ }
+
+ ///
+ /// 获取最终的设备唯一机器码
+ ///
+ public static string GetDeviceMachineCode()
+ {
+ string cpuId = GetCpuId();
+ string boardId = GetMotherboardId();
+
+ // 将主板和CPU序列号拼接,并转换为MD5,生成一个干净的、固定长度的机器码
+ string rawCode = $"CPU:{cpuId}_BOARD:{boardId}";
+ return GetMD5Hash(rawCode);
+ }
+
+ ///
+ /// 获取 CPU 序列号
+ ///
+ 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";
+ }
+
+ ///
+ /// 获取主板序列号 (最稳定的硬件标识)
+ ///
+ 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";
+ }
+
+ ///
+ /// 字符串 MD5 加密
+ ///
+ 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();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/UIShare/UIShare.csproj b/UIShare/UIShare.csproj
index 60b5c1e..0bb28bb 100644
--- a/UIShare/UIShare.csproj
+++ b/UIShare/UIShare.csproj
@@ -16,6 +16,7 @@
+