6

我想要后端服务 (ws) 的唯一设备 ID,因为我发现以下参考

  private string GetDeviceId()
    {
        var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
        var hardwareId = token.Id;
        var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);

        byte[] bytes = new byte[hardwareId.Length];
        dataReader.ReadBytes(bytes);

        return BitConverter.ToString(bytes).Replace("-", "");
    }//Note: This function may throw an exception. 

但是,我无法理解代码,每次我为我的设备(64 个字符串)获得相同的 ID 时,我想知道它是否适用?我也找不到 MSDN 的任何参考资料

谢谢

4

1 回答 1

2

这可能会有所帮助:

private string GetDeviceID()
{
    HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
    IBuffer hardwareId = token.Id;

    HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
    IBuffer hashed = hasher.HashData(hardwareId);

    string hashedString = CryptographicBuffer.EncodeToHexString(hashed);
    return hashedString;
}

有关文档,请查看HardwareIdentification类中的GetPackageSpecificToken方法。

于 2015-08-21T11:27:09.350 回答