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 @@ +