XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Security.Cryptography;
using System.Text;

namespace XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;

/// <summary>
/// 跨平台实例标识帮助。不会读取 CPU、主板、BIOS 或磁盘序列号。
/// </summary>
public static class DeviceHelper
{
    /// <summary>
    /// 获取由 XFE_DEVICE_ID 显式配置的实例标识;未配置时使用机器名的不可逆摘要。
    /// </summary>
    [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)));
    }
}