forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceIdHelper.cs
More file actions
59 lines (52 loc) · 1.76 KB
/
DeviceIdHelper.cs
File metadata and controls
59 lines (52 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Application.Services;
using System.Security.Cryptography;
using System.Linq;
using System.Application.Models;
using _Constants = System.Common.Constants;
namespace System.Application
{
public static partial class DeviceIdHelper
{
static Guid GetGuid(string key)
{
var value = Preferences2.Get(key, null);
if (!(!string.IsNullOrWhiteSpace(value) && ShortGuid.TryParse(value, out Guid guid)))
{
guid = Guid.NewGuid();
Preferences2.Set(key, guid.ToStringS());
}
return guid;
}
static string Get(string key)
{
var value = Preferences2.Get(key, null);
if (string.IsNullOrWhiteSpace(value))
{
value = Random2.GenerateRandomString(DeviceIdRLength, _Constants.DigitsLetters);
Preferences2.Set(key, value);
}
return value;
}
static Guid DeviceIdG => GetGuid("KEY_DEVICE_ID_G");
static string DeviceIdR => Get("KEY_DEVICE_ID_R");
static string DeviceIdN
{
get
{
var s = IPlatformService.Instance;
(var key, var iv) = s.MachineSecretKey;
var data = key.FirstOrDefault() % 2 == 0 ? key.Concat(iv) : iv.Concat(key);
return Hashs.String.SHA256(data.ToArray(), isLower: false);
}
}
public static void SetDeviceId(this ActiveUserRecordDTO value)
{
var deviceIdG = DeviceIdG;
var deviceIdR = DeviceIdR;
var deviceIdN = DeviceIdN;
value.DeviceIdG = deviceIdG;
value.DeviceIdR = deviceIdR;
value.DeviceIdN = deviceIdN;
}
}
}