How to get the device unique id in Windows Phone 8.1? The old way of using DeviceExtendedProperties.GetValue("DeviceUniqueId")
does not work for Windows Universal app.
Asked
Active
Viewed 1.2k times
28

Rhys
- 4,511
- 2
- 23
- 32

MohanRajNK
- 895
- 2
- 13
- 26
-
Any examples? I'm asking this question here, as well: http://stackoverflow.com/questions/36004003/windows-phone-device-unique-id – Glenn Strycker Jul 22 '16 at 16:01
2 Answers
32
private string GetDeviceID()
{
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = token.Id;
HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm("MD5");
IBuffer hashed = hasher.HashData(hardwareId);
string hashedString = CryptographicBuffer.EncodeToHexString(hashed);
return hashedString;
}
Hope this help !

Robert MacLean
- 38,975
- 25
- 98
- 152

thongaduka
- 627
- 1
- 8
- 19
-
-
9I would replace "MD5" to [HashAlgorithmNames.Md5](http://msdn.microsoft.com/en-us/library/windows.security.cryptography.core.hashalgorithmnames.md5.aspx). – Alexander.Ermolaev Oct 16 '14 at 12:24
-
You can replace CryptographicBuffer.EncodeToHexString with Convert.ToBase64String, it will produce shorter but still readable string. – Grigory Nov 05 '15 at 15:42
23
Note that when you write Universal App, it can be installed not only on phone. While on Phone technically hardware configuration is the same, on other devices it can change and so its ID. That's I think there is no such universal method to get ID. (more information you can find also here).
You may have a look at HardwareIdentification class and its method GetPackageSpecificToken:
HardwareToken myToken = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = myToken.Id;
There is also a Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic.
-
2If you want to use it you must remember, that this Id will change when you change the app signing certificate – Johniak Sep 03 '15 at 12:27
-
-
@Romasz `HardwareIdentification.GetPackageSpecificToken` is dependent on Package id/name. Is there any other ID which appears same for all apps installed on same device? – Kinjan Bhavsar Sep 16 '16 at 05:39
-
-
@Romasz Can you confirm whether it will unique for each device( i.e if I install same app in two devices, I will get different hardware id ) ? Also, if both devices are same then also we will get different hardware id? – Kinjan Bhavsar Sep 16 '16 at 12:38
-