Files
MRCC/launcher/PCL-CE/PCL.Core/Utils/Secret/IdentifyOld.cs
T
xyou f70b061d1a
CI / Go Backend (push) Canceled after 0s
feat: 项目初始化 + 3D方块世界原型 + AI助搭系统
初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器

HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块

Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚

AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
2026-08-08 14:07:56 +08:00

103 lines
3.3 KiB
C#

using System;
using System.Management;
using PCL.Core.App;
using PCL.Core.Logging;
using PCL.Core.Utils.Hash;
using PCL.Core.Utils.Exts;
namespace PCL.Core.Utils.Secret;
[Obsolete("Use PCL.Core.Utils.Secret.Identify instead")]
public static class IdentifyOld
{
private const string DefaultRawCode = "B09675A9351CBD1FD568056781FE3966DD936CC9B94E51AB5CF67EEB7E74C075";
private static readonly Lazy<string?> _LazyCpuId = new(_GetCpuId);
private static readonly Lazy<string> _LazyRawCode =
new(() => CpuId is null ? DefaultRawCode : SHA256Provider.Instance.ComputeHash(CpuId).ToHexString().ToUpper());
private static readonly Lazy<string> _LaunchId = new(_GetLaunchId);
private static readonly Lazy<string> _LazyEncryptKey =
new(() => SHA512Provider.Instance.ComputeHash(RawCode).ToHexString().Substring(4, 32).ToUpper());
public static string GetGuid() => Guid.NewGuid().ToString();
[Obsolete]
public static string? CpuId => _LazyCpuId.Value;
[Obsolete]
public static string RawCode => _LazyRawCode.Value;
[Obsolete]
public static string LaunchId => _LaunchId.Value;
[Obsolete]
public static string EncryptKey => _LazyEncryptKey.Value;
private static string? _GetCpuId()
{
try
{
using var searcher = new ManagementObjectSearcher("SELECT ProcessorId FROM Win32_Processor");
using var collection = searcher.Get();
foreach (var item in collection)
{
try
{
return item["ProcessorId"]?.ToString();
}
catch (ManagementException ex)
{
LogWrapper.Warn("Identify", $"WMI属性读取失败: {ex.Message}");
}
finally
{
item.Dispose();
}
}
LogWrapper.Warn("Identify", "未找到有效的CPU ID");
return null;
}
catch (ManagementException ex)
{
LogWrapper.Error(ex, "Identify", $"WMI查询失败");
}
catch (System.Runtime.InteropServices.COMException ex)
{
LogWrapper.Error(ex, "Identify", $"COM异常,请确保WMI服务正在运行");
}
catch (UnauthorizedAccessException ex)
{
LogWrapper.Error(ex, "Identify", "访问被拒绝,请以管理员权限运行");
}
catch (Exception ex)
{
LogWrapper.Error(ex, "Identify", $"意外的系统异常");
}
return null;
}
public static string GetMachineId(string randomId)
{
return SHA512Provider.Instance.ComputeHash($"{randomId}|{CpuId}").ToHexString().ToUpper();
}
private static string _GetLaunchId()
{
try
{
if (string.IsNullOrEmpty(States.System.LaunchUuid)) States.System.LaunchUuid = GetGuid();
var hashCode = GetMachineId(States.System.LaunchUuid)
.Substring(6, 16)
.Insert(4, "-")
.Insert(9, "-")
.Insert(14, "-");
return hashCode;
}
catch (Exception ex)
{
LogWrapper.Error(ex, "Identify", "无法获取短识别码");
return "PCL2-CECE-GOOD-2025";
}
}
}