using System.Security.Cryptography; using System.Text; namespace XFEExtension.NetCore.ServerInteractive.Utilities.Helpers; /// /// 跨平台实例标识帮助。不会读取 CPU、主板、BIOS 或磁盘序列号。 /// public static class DeviceHelper { /// /// 获取由 XFE_DEVICE_ID 显式配置的实例标识;未配置时使用机器名的不可逆摘要。 /// [Obsolete("请在 XFEClientRequesterOptions.DeviceInfo 中显式配置实例标识")] public static string GetUniqueHardwareId() { var configured = Environment.GetEnvironmentVariable("XFE_DEVICE_ID"); var source = string.IsNullOrWhiteSpace(configured) ? Environment.MachineName : configured; return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(source))); } }