/// <summary> /// Compute a stable application specific client instance id string for use as "clientInstanceId" parameters in IXboxMusicClient /// </summary> /// <returns>A valid clientInstanceId string. This string is specific to the current machine, user and application.</returns> private static string ComputeClientInstanceId() { // Generate a somewhat stable application instance id HardwareToken ashwid = HardwareIdentification.GetPackageSpecificToken(null); byte[] id = ashwid.Id.ToArray(); string idstring = Package.Current.Id.Name + ":"; for (int i = 0; i < id.Length; i += 4) { short what = BitConverter.ToInt16(id, i); short value = BitConverter.ToInt16(id, i + 2); // Only include stable components in the id // http://msdn.microsoft.com/en-us/library/windows/apps/jj553431.aspx const int cpuId = 1; const int memorySize = 2; const int diskSerial = 3; const int bios = 9; if (what == cpuId || what == memorySize || what == diskSerial || what == bios) { idstring += value.ToString("X4"); } } return(idstring.PadRight(32, 'X')); }
private static string GetDeviceInfo() { var hash = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512).CreateHash(); hash.Append(HardwareIdentification.GetPackageSpecificToken(null).Id); return(CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset())); }
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\ #region --Attributes-- #endregion //--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- #endregion //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\ #region --Set-, Get- Methods-- /// <summary> /// Returns a hex string representing an unique device ID. /// The device ID is a SHA256 hash, hex string of the actual device ID XOR a device nonce to prevent tracking between apps. /// </summary> public static string GetUniqueDeviceId() { byte[] deviceId; SystemIdentificationInfo systemId = SystemIdentification.GetSystemIdForPublisher(); if (systemId.Source != SystemIdentificationSource.None) { deviceId = systemId.Id.ToArray(); } else { // Fall back to generating a unique ID based on the hardware of the system. // This ID will change once the hardware changes. // Based on: https://montemagno.com/unique-device-id-for-mobile-apps/ HardwareToken hwToken = HardwareIdentification.GetPackageSpecificToken(null); deviceId = hwToken.Id.ToArray(); } byte[] nonce = GetDeviceNonce(); // Ensure the device ID is long enough: deviceId = deviceId.Length >= 32 ? XorShorten(deviceId, nonce) : nonce; SHA256 sha = SHA256.Create(); deviceId = sha.ComputeHash(deviceId); return(ByteArrayToHexString(deviceId)); }
/// <summary> /// 开始发送使用信息 /// </summary> /// <param name="mod"></param> private async void Begin_tongji_Run(string mod) { try { ClassHttp CH = new ClassHttp(); CH.HttpURL = URLSTR.tongji; IDictionary <string, string> CS = new Dictionary <string, string>(); //可选参数,但如果要获取的地址不是网页,而是一个文件或图片,服务器一般默认配置不接受Post进而导致无法获取到。 //直接使用图片地址的,不要设置这个参数,避免使用Post方式,直接传递null。 HardwareToken hardwareToken = HardwareIdentification.GetPackageSpecificToken(null); EasClientDeviceInformation easClientDeviceInformation = new EasClientDeviceInformation(); CS["mod"] = mod; CS["hardwareToken_Id"] = Buffer2Base64(hardwareToken.Id); CS["hardwareToken_Signature"] = Buffer2Base64(hardwareToken.Signature); CS["hardwareToken_Certificate"] = Buffer2Base64(hardwareToken.Certificate); CS["easClientDeviceInformation_Version"] = "固件版本:" + easClientDeviceInformation.SystemFirmwareVersion + "★硬件版本:" + easClientDeviceInformation.SystemHardwareVersion; CS["easClientDeviceInformation_FriendlyName"] = easClientDeviceInformation.FriendlyName; CS["easClientDeviceInformation_OperatingSystem"] = easClientDeviceInformation.OperatingSystem; CS["easClientDeviceInformation_SystemManufacturer"] = easClientDeviceInformation.SystemManufacturer; CS["easClientDeviceInformation_SystemProductName"] = easClientDeviceInformation.SystemProductName; IDictionary <string, object> RE = await CH.LoadHttpText(CS); } catch (Exception exx) { } }
/// <summary> /// Returns device id /// </summary> public static string GetDeviceId() { var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; return(CryptographicBuffer.EncodeToHexString(hardwareId)); }
private async Task GetUserInfoAsync() { if ((await User.FindAllAsync()).Where(p => p.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated && p.Type == UserType.LocalUser).FirstOrDefault() is User CurrentUser) { string UserName = (await CurrentUser.GetPropertyAsync(KnownUserProperties.FirstName))?.ToString(); string UserID = (await CurrentUser.GetPropertyAsync(KnownUserProperties.AccountName))?.ToString(); if (string.IsNullOrEmpty(UserID)) { var Token = HardwareIdentification.GetPackageSpecificToken(null); HashAlgorithmProvider md5 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5); IBuffer hashedData = md5.HashData(Token.Id); UserID = CryptographicBuffer.EncodeToHexString(hashedData).ToUpper(); } if (string.IsNullOrEmpty(UserName)) { UserName = UserID.Substring(0, 10); } ApplicationData.Current.LocalSettings.Values["SystemUserName"] = UserName; ApplicationData.Current.LocalSettings.Values["SystemUserID"] = UserID; } else { var Token = HardwareIdentification.GetPackageSpecificToken(null); HashAlgorithmProvider md5 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5); IBuffer hashedData = md5.HashData(Token.Id); string UserID = CryptographicBuffer.EncodeToHexString(hashedData).ToUpper(); string UserName = UserID.Substring(0, 10); ApplicationData.Current.LocalSettings.Values["SystemUserName"] = UserName; ApplicationData.Current.LocalSettings.Values["SystemUserID"] = UserID; } }
public static string GetDeviceId() { var nonce = CryptographicBuffer.ConvertStringToBinary("0.1", BinaryStringEncoding.Utf8); var ashwid = HardwareIdentification.GetPackageSpecificToken(nonce); var accum = new Dictionary <Component, int>(); var idstream = ashwid.Id.AsStream(); for (int i = 0; i < idstream.Length; i += 4) { var componentID = (Component)((idstream.ReadByte() << 8) | idstream.ReadByte()); var componentValue = (idstream.ReadByte() << 8) | idstream.ReadByte(); switch (componentID) { case Component.Processor: case Component.SystemBIOS: case Component.Memory: accum[componentID] = accum.GetValueOrDefault(componentID) + componentValue; break; default: break; } } var pid = accum.GetValueOrDefault(Component.Processor).ToString("x"); var sid = accum.GetValueOrDefault(Component.SystemBIOS).ToString("x"); var mid = accum.GetValueOrDefault(Component.Memory).ToString("x"); return($"{pid}-{sid}-{mid}"); }
#pragma warning restore 1998 /// <summary> /// Gets the device unique identifier. /// </summary> /// <returns>The discovered device identifier.</returns> public virtual string GetDeviceUniqueId() { string deviceId = null; try { // Per documentation here http://msdn.microsoft.com/en-us/library/windows/apps/jj553431.aspx we are selectively pulling out // specific items from the hardware ID. StringBuilder builder = new StringBuilder(); HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null); using (DataReader dataReader = DataReader.FromBuffer(token.Id)) { int offset = 0; while (offset < token.Id.Length) { // The first two bytes contain the type of the component and the next two bytes contain the value. byte[] hardwareEntry = new byte[4]; dataReader.ReadBytes(hardwareEntry); if ((hardwareEntry[0] == 1 || // CPU ID of the processor hardwareEntry[0] == 2 || // Size of the memory hardwareEntry[0] == 3 || // Serial number of the disk device hardwareEntry[0] == 7 || // Mobile broadband ID hardwareEntry[0] == 9) && // BIOS hardwareEntry[1] == 0) { if (builder.Length > 0) { builder.Append(','); } builder.Append(hardwareEntry[2]); builder.Append('_'); builder.Append(hardwareEntry[3]); } offset += 4; } } // create a buffer containing the cleartext device ID IBuffer clearBuffer = CryptographicBuffer.ConvertStringToBinary(builder.ToString(), BinaryStringEncoding.Utf8); // get a provider for the SHA256 algorithm HashAlgorithmProvider hashAlgorithmProvider = HashAlgorithmProvider.OpenAlgorithm("SHA256"); // hash the input buffer IBuffer hashedBuffer = hashAlgorithmProvider.HashData(clearBuffer); deviceId = CryptographicBuffer.EncodeToBase64String(hashedBuffer); } catch (Exception) { // For IoT sceanrios we will alwasy set the device id to IoT // Becuase HardwareIdentification API will always throw deviceId = "IoT"; } return(deviceId); }
//get device id public static string getDeviceId() { string APP_UNIQ_ID = "APP_UNIQ_ID"; string cachedStr = ApplicationSettings.GetSetting <string>(APP_UNIQ_ID, null); if (!string.IsNullOrEmpty(cachedStr) && cachedStr.Length <= 32 && cachedStr.IndexOf('-') < 0) { return(cachedStr); } string tokenStr; var token = HardwareIdentification.GetPackageSpecificToken(null); var stream = token.Id.AsStream(); using (var reader = new BinaryReader(stream)) { byte[] bytes = reader.ReadBytes((int)stream.Length); tokenStr = ComputeMD5(bytes); //use md5 to save some space } //remove the - from id string to save space //tokenStr=tokenStr.Replace("-",""); ApplicationSettings.SetSetting <string>(APP_UNIQ_ID, tokenStr); return(tokenStr); }
public void InitializeValues(string advId, string advKey) { var hardwareId = HardwareIdentification.GetPackageSpecificToken(null).Id; var dataReader = DataReader.FromBuffer(hardwareId); byte[] bytes = new byte[hardwareId.Length]; dataReader.ReadBytes(bytes); this.parameters = new Parameters(advId, advKey, bytes); eventQueue = new MATEventQueue(parameters); GetUserAgent(); // Handles the OnNetworkStatusChange event NetworkStatusChangedEventHandler networkStatusCallback = null; // Indicates if the connection profile is registered for network status change events. Set the default value to FALSE. bool registeredNetworkStatusNotif = false; networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange); // Register for network status change notifications if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusCallback; registeredNetworkStatusNotif = true; } // Send queued requests eventQueue.DumpQueue(); }
public Registration(DataPersistance dp, string EngineName) { this.dp = dp; this.EngineName = EngineName; Vars = dp.GetVariables("License"); _AppName = dp.GetVariable <string>("System", "AppName", string.Empty); UserName = Vars.GetVariable <string>("UserName", string.Empty); CompanyName = Vars.GetVariable <string>("CompanyName", string.Empty); Limitation = Vars.GetVariable <int>("Limitation", 0); MonthLimitation = Vars.GetVariable <int>( "MonthLimitation", 6); _RegistrationNo = HardwareIdentification.Pack( HardwareIdentification.Value() + _AppName); ActivationCode = Vars.GetVariable <string>( EngineName + _RegistrationNo, string.Empty); if (Limitation < 0 || Limitation > 2) { Limitation = 0; } IsOldValidReg = IsValidActivationCode() && Limitation != 0; }
private string GetDeviceIdentifyId() { string deviceUniqeId = string.Empty; try { if (ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification")) { var packageSpecificToken = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = packageSpecificToken.Id; var hasher = HashAlgorithmProvider.OpenAlgorithm("MD5"); var hashedHardwareId = hasher.HashData(hardwareId); deviceUniqeId = CryptographicBuffer.EncodeToHexString(hashedHardwareId); return(deviceUniqeId); } } catch (Exception) { // XBOX 目前會取失敗 } // support IoT Device var networkProfiles = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles(); var adapter = networkProfiles[0].NetworkAdapter; string networkAdapterId = adapter.NetworkAdapterId.ToString(); deviceUniqeId = networkAdapterId.Replace("-", string.Empty); return(deviceUniqeId); }
public WindowsStoreDeviceInfoService() { this.deviceId = new Lazy <string>(() => { HardwareToken myToken = HardwareIdentification.GetPackageSpecificToken(null); return(myToken.Id.ToString()); }); switch (GetScaleFactor()) { case 150: this.ScreenWidth = 720; this.ScreenHeight = 1280; break; case 160: this.ScreenWidth = 768; this.ScreenHeight = 1280; break; case 100: default: this.ScreenWidth = 480; this.ScreenHeight = 800; break; } }
public static ImageTestResultConnection GetDefaultImageTestResultConnection() { var result = new ImageTestResultConnection(); // TODO: Check build number in environment variables result.BuildNumber = -1; #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP result.Platform = "Windows"; result.Serial = Environment.MachineName; #if SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D12 result.DeviceName = "Direct3D12"; #elif SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D11 result.DeviceName = "Direct3D"; #elif SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES result.DeviceName = "OpenGLES"; #elif SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGL result.DeviceName = "OpenGL"; #endif #elif SILICONSTUDIO_PLATFORM_ANDROID result.Platform = "Android"; result.DeviceName = Android.OS.Build.Manufacturer + " " + Android.OS.Build.Model; result.Serial = Android.OS.Build.Serial ?? "Unknown"; #elif SILICONSTUDIO_PLATFORM_IOS result.Platform = "iOS"; result.DeviceName = iOSDeviceType.Version.ToString(); result.Serial = UIKit.UIDevice.CurrentDevice.Name; #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME #if SILICONSTUDIO_PLATFORM_WINDOWS_PHONE result.Platform = "WindowsPhone"; #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE result.Platform = "WindowsStore"; #else result.Platform = "Windows10"; #endif var deviceInfo = new EasClientDeviceInformation(); result.DeviceName = deviceInfo.SystemManufacturer + " " + deviceInfo.SystemProductName; try { result.Serial = deviceInfo.Id.ToString(); } catch (Exception) { #if SILICONSTUDIO_PLATFORM_WINDOWS_PHONE || SILICONSTUDIO_PLATFORM_WINDOWS_STORE var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; var hasher = HashAlgorithmProvider.OpenAlgorithm("MD5"); var hashed = hasher.HashData(hardwareId); result.Serial = CryptographicBuffer.EncodeToHexString(hashed); #else // Ignored on Windows 10 #endif } #endif return(result); }
private void UpdateStoredChannelUri(String uri) { // Retrieve an encrypted, machine & app specific id so the server can know what uri goes with what system var hardwareToken = HardwareIdentification.GetPackageSpecificToken(null); var systemIdentifier = CryptographicBuffer.EncodeToBase64String(hardwareToken.Id); // Simulate "sending" the Channel Uri update to the server by storing it in static memory SendNotificationHelper.StoreChannel(systemIdentifier, uri); }
public static string GetDeviceID() { // Vedran: A very big thanks to Matija Leskovar for contribution. // https://github.com/matijaleskovar // retrieve the ID bytes byte[] hwIDBytes = HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray(); // map reduce the ID... fun... return(hwIDBytes.Select(b => b.ToString()).Aggregate((b, next) => b + next)); }
public static string GetDeviceId() { HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null); IBuffer hardwareId = token.Id; HashAlgorithmProvider hasher = HashAlgorithmProvider.OpenAlgorithm("MD5"); IBuffer hashed = hasher.HashData(hardwareId); return(CryptographicBuffer.EncodeToHexString(hashed)); }
public string GetDeviceID() { var token = HardwareIdentification.GetPackageSpecificToken(null); IBuffer buffer = token.Id; var md5Provider = HashAlgorithmProvider.OpenAlgorithm("MD5"); var hashdata = md5Provider.HashData(buffer); return(CryptographicBuffer.EncodeToHexString(hashdata)); }
public string GetIdentifier() { var token = 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("-", "").Substring(0, 15)); }
private static string GetHardwareId() { var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; var dataReader = DataReader.FromBuffer(hardwareId); byte[] bytes = new byte[hardwareId.Length]; dataReader.ReadBytes(bytes); return(Convert.ToBase64String(bytes)); }
/// Get the local device's name /// </summary> /// <returns>Unique ID for the device</returns> public String GetUniqueId() { var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId); byte[] bytes = new byte[8]; dataReader.ReadBytes(bytes); return(Pairing.bytesToHex(bytes)); }
private static string GetHardwareId() { var token = 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)); }
static string GetDeviceIdImpl() { HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null); IBuffer hardwareId = token.Id; var dataReader = DataReader.FromBuffer(hardwareId); var bytes = new byte[hardwareId.Length]; dataReader.ReadBytes(bytes); return(BitConverter.ToString(bytes)); }
/// <summary> ///获取设备唯一ID /// </summary> /// <returns></returns> public static string GetUniqueDeviceId() { HardwareToken ht = HardwareIdentification.GetPackageSpecificToken(null); var id = ht.Id; var dataReader = DataReader.FromBuffer(id); byte[] bytes = new byte[id.Length]; dataReader.ReadBytes(bytes); string s = BitConverter.ToString(bytes); return(s.Replace("-", "")); }
public override string GetDeviceId() { var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; var hasher = HashAlgorithmProvider.OpenAlgorithm("MD5"); var hashed = hasher.HashData(hardwareId); var hashedString = CryptographicBuffer.EncodeToHexString(hashed); return(hashedString); }
/// <summary> /// Gets the device unique identifier. /// </summary> /// <returns>The device unique identifier.</returns> private static string GetDeviceId() { // Get the hardware ID var token = HardwareIdentification.GetPackageSpecificToken(null); var hardwareId = token.Id; // Hash the data var hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5); var hashed = hasher.HashData(hardwareId); return(CryptographicBuffer.EncodeToHexString(hashed)); }
/// <summary> /// It is recommended you generate a way that is unique for the app/device. In this example we normalize the hardware /// ID for things that rarely change and add a few strings related to the app. /// See http://code.msdn.microsoft.com/windowsapps/How-to-use-ASHWID-to-3742c83e for examples on ASHWID use. /// </summary> /// <returns></returns> private static string GetDeviceUniqueId() { HardwareToken id = HardwareIdentification.GetPackageSpecificToken(null); string normalized = NormalizeHardwareId(id.Id.ToArray()); HashAlgorithmProvider alg = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames); IBuffer buff = CryptographicBuffer.ConvertStringToBinary(normalized + typeof(HmacSHA256KeyGenerator).FullName, BinaryStringEncoding.Utf8); IBuffer hashed = alg.HashData(buff); return(CryptographicBuffer.EncodeToHexString(hashed)); }
/// <summary> /// Retrieve a unique ID that is stable across application instances, similar to what /// Unity does with SystemInfo.deviceUniqueIdentifier. /// </summary> /// <param name="variant">Optional variation quantity to modify the unique ID, /// to allow multiple instances of the application to run in parallel with different IDs.</param> /// <returns>A unique string ID stable across multiple runs of the application</returns> /// <remarks> /// This is a debugging utility useful to generate deterministic WebRTC peers for node-dss /// signaling, to avoid manual input during testing. This is not a production-level solution. /// </remarks> private string GetDeviceUniqueIdLikeUnity(byte variant = 0) { // More or less like Unity, which can use HardwareIdentification.GetPackageSpecificToken() in some cases, // although it's unclear how they convert that to a string. Windows.Storage.Streams.IBuffer buffer = HardwareIdentification.GetPackageSpecificToken(null).Id; using (var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(buffer)) { byte[] bytes = new byte[buffer.Length]; dataReader.ReadBytes(bytes); bytes[0] += variant; return(BitConverter.ToString(bytes).Replace("-", string.Empty).Remove(32)); } }
private static string GetDeviceId() { if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification")) { var token = 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("-", "")); } return("DEVICE-ID-NOT-FOUND"); }
private async static void SetChannel() { var pushNotifier = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var token = HardwareIdentification.GetPackageSpecificToken(null); // get this for the specific hardware to id the device being used string installationId = CryptographicBuffer.EncodeToBase64String(token.Id); var channel = new JsonObject { { "ChannelUri", JsonValue.CreateStringValue(pushNotifier.Uri) }, { "InstallationId", JsonValue.CreateStringValue(installationId) } }; await App.MobileService.GetTable("Channels").InsertAsync(channel); }