Several scenarios for the Windows store app to get the device ID

Source: Internet
Author: User
Tags intel core i5

This article is a personal blog backup article, the original address:

http://validvoid.net/solutions-get-device-id-for-uwp/

Data statistics by generating a unique device ID is a very common requirement in application development, however since WP 7.8, the WP platform can no longer get a unique, unchanging, and different applications of the same device ID. This paper summarizes several schemes used for statistical device IDs on the Windows Store platform, which can be selected according to the specific requirements when developing.

1. AD ID

The ad ID is primarily used to optimize the relevance and frequency of ad pushes by analyzing which apps the user installs and how they are used, as well as to detect ad fraud and other security issues.

 Public Static string get; }
Characteristics
    • Per-user, per-device unique
    • Consistency between applications
Disadvantages
    • The ad ID is not continuously available, and the user can turn off the ad ID in the privacy Options or Group Policy settings of the system.
    • The ad ID is not permanently unique, and the following conditions can cause the ad ID to change:
      • The ad ID is regenerated after the user turns off the ad ID after closing the ad ID.
      • After the user resets or upgrades the operating system of the device (phone, PC, and so on), the ad ID is regenerated.
    • Because the ad ID is unique per user and Per device, the ad ID does not roam across devices with the user account.
    • The ad ID cannot be opened in the child account.
How to use
var advertisingid = Windows.System.UserProfile.AdvertisingManager.AdvertisingId;

When the ad ID is closed, use the API above to get the return value of the Ad ID blank.

MSDN Documentation

Advertisingmanager.advertisingid | Advertisingid Property

2. Easclientdeviceinformation

The Easclientdeviceinformation class is used to obtain information about a local exchangeactivesync device. There is an id attribute for the Guid type that can get the device ID.

 Public get; }

Returns the identifier of the local computer. The Id attribute represents DeviceId (thefirst 16 character GUIDs that are truncated with the SHA256 hash value from MachineID, user SID 1, and package family name (PFN)2, where MachineID uses the SID of the local user group). Each component of the GUID is returned in network byte order.

Characteristics
    • Unique per-user, per-device, per-app
Disadvantages
    • Unique per application

Because the element that constitutes the EAS client device information ID contains the package family name (PFN), the EAS client device information ID is unique between each application. Assuming that you have multiple apps that are data-counted through the device's unique ID, two apps on the same device will return two different IDs.

How to use
var New Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation (). Id;

MSDN Documentation

Easclientdeviceinformation class

3. Apply a specific hardware ID (ASHWID)

Application-Specific hardware ID (abbreviated as ASHWID) enables the identification of unique devices by performing device hardware features. Ashwid is intended to limit the number of app distribution target devices, or to restrict the use of unique authorizations per device.

Characteristics
    • Per Device, per app unique
    • Consistent between users
    • does not change because of the following actions:
      • Operating System reinstallation
      • Push button Reset
      • Operating system SKU Upgrade
      • Version updates for Apps
      • Change users on the same device
    • Verifiable authenticity
Disadvantages
    • The value will change as the device hardware changes
The composition of the Ashwid

Ashwid is generated by the component hardware of the current device and the current application package name.

Ashwid is generated according to the following nine possible hardware components, each of which corresponds to a portion of the byte stream returned by the Ashwid:

    1. CPU ID of the processor
    2. Memory size
    3. Serial number of the disk device
    4. Network adapter (for example, NIC MAC address)
    5. Audio Adapter
    6. Docking station
    7. Bluetooth Address
    8. Mobile Broadband Device ID
    9. Bios

Ashwid may not contain exactly 9 component IDs. Possible causes include the following:

    • The target hardware may not have exactly 9 separate components. For example, the desktop may not have a docking station.
    • Devices may have multiple components of the same type. For example, there may be two audio adapters.
    • Each physical disk drive corresponds to a component ID. A desktop system with 3 physical disk drives returns 3 component IDs.
    • When a tablet device is connected to a docking station, it returns the component ID of the other network (Ethernet) adapter and the audio adapter (from the HDMI or analog audio output port).

The Ashwid byte stream identifies the type and value of the hardware component and participates in the following table:

byte stream representation Components
1,0 Processor
2,0 Memory
3,0 Disk devices
4,0 Network adapter
5,0 Audio Adapter
6,0 Docking station
7,0 Mobile Broadband
8,0 Bluetooth
9,0 System BIOS

The above table is excerpted from the MSDN documentation.

For privacy reasons, the Ashwid generation considers the application package name, so that the Ashwid is different for two apps on the same device. And as long as the device hardware does not change, the same application on the same device multiple times obtained ashwid is always the same.

Ashwid Example

The enumeration order of different component IDs is not necessarily contiguous. Displays a small number of ashwid examples as dirty. Note that in a stream, the number of component IDs and their order will be different.

7,0,124,215,3,0,206,143,8,0,128,55,5,0,12,222,5,0,128,255,6,0,1,0,4,0,20,22,4,0,48,155,1,0,250,155,2,0,162,217,9,0,92,101

Mobile broadband found on Samsung Intel Core i5 tablets.

7,0,124,215,3,0,206,143,8,0,128,55,5,0,126,129,5,0,12,222,5,0,128,255,6,0,1,0,4,0,20,22,4,0,48,155,4,0,178,193,1,0,250,15 5,2,0,162,217,9,0,92,101

When connected, there are three different audio adapters on the same device and three different network adapters on the same device when connected.

3,0,188,97,3,0,76,128,3,0,250,138,5,0,220,130,6,0,1,0,4,0,20,164,1,0,204,49,2,0,226,37,9,0,22,72

Three different disks were found on the desktop.

3,0,24,211,5,0,182,46,5,0,54,49,6,0,1,0,4,0,203,9,1,0,148,99,2,0,162,255,9,0,140,234

Nvidia Tegra 3 devices. You may notice that the flow "6,0,1,0" corresponds to the docking station, regardless of the device or form factor.

The above example is excerpted from the MSDN documentation.

How to use

To get Ashwid, you can use the Hardwareidentification.getpackagespecifictoken method.

The method accepts a parameter IBuffer nonce . nonceto a number that is used only once. Typically, this number is implemented as a random number, which is large enough to reduce the likelihood of a digital re-use. nonceused in authentication protocols to prevent replay attacks.

The method returns a HardwareToken type. The HardwareToken type represents a token that contains a sufficiently unique hardware-based identity.

HardwareTokenThe type contains the following three attributes (both IBuffer ):

    • Certificate: Obtain the certificate that is used to sign the hardware-specific ID to verify the ID authenticity.
    • Id: Gets the hardware-specific Id.
    • Signature: Obtain the signature of the hardware-specific ID to verify the ID authenticity.
=  Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken (nonce); IBuffer HardwareID  = = = packagespecifictoken.certificate;  var dataReader = Windows.Storage.Streams.DataReader.FromBuffer (hardwareid);   byte New byte [hardwareid.length];  Datareader.readbytes (bytes);   string id = bitconverter.tostring (bytes);

Verifying Ashwid Validity

To use Ashwid to implement genuine authorization validation, limit application distribution, and so on, you can validate by using an optional nonce, signature, and certificate in the cloud with your app.

When you call a GetPackageSpecificToken method, you can pass in IBuffer a parameter of the type nonce . By providing a different nonce each time, the cloud can then verify that the returned Ashwid are actually from Windows and are not replayed by the user.

It is not recommended to pass an empty nonce for a method unless the cloud does not care about replay attacks or ashwid processing is done only on the client GetPackageSpecificToken .

As the Ashwid will change with the hardware of the device, it is necessary to calculate the change amount of ashwid in response to the cloud in verifying the ashwid, and to judge the validity of the license authorization within the allowable range.

For more instructions on verifying ashwid in the cloud, you can refer to the MSDN documentation for a guide to implementing per-device application logic using app-specific hardware IDs (ASHWID).

    1. The SID full name is Security Identifier, which is the "secure identifier". SIDs are published by authoritative parties such as Windows domain controllers to identify users, user groups, and computer accounts. Each account created will have a unique SID assigned to the account. Even if you delete an account and create a new account with exactly the same name, the new account's SID is different from the old one. When a user logs on, the SID is used by the system as part of the user's access credentials to determine whether the current user has permission to perform an action. For more information about SIDS, refer to document Security Identifiers.

    2. The package family name (PFN), which is the name of the bundle that is linked to the hashed publisher name.

Several scenarios for the Windows store app to get the device ID

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.