C# 如何获取windows phone 8.1的设备唯一Id?

C# 如何获取windows phone 8.1的设备唯一Id?,c#,windows-phone-8.1,unique-id,C#,Windows Phone 8.1,Unique Id,我需要后端服务(ws)的唯一设备Id,我在下面的引用中找到了它 private string GetDeviceId() { var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; var dataReader = Windows.Storage.Streams.

我需要后端服务(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. 
但是,我不能理解代码,每次我为我的设备获得相同的Id(64个字符串),我想知道它是否适用? 我也找不到MSDN的任何参考资料

谢谢

这可能会有帮助:

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;
}

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

您可以使用
HashAlgorithmNames.MD5
@KristianVukusic来代替硬编码的“MD5”。谢谢。我已经更新了我的答案。一旦您更改了硬件配置文件(拔下BT或其他东西),此PackageSpecificToken就会更改。我不相信它。可能只是为了广告目的。无论如何,如果你使用它,你应该处理它的“漂移”: