diff --git a/EgwCoreLib.BlazorTest/Data/TestData.cs b/EgwCoreLib.BlazorTest/Data/TestData.cs
index 8596a96..da6bd65 100644
--- a/EgwCoreLib.BlazorTest/Data/TestData.cs
+++ b/EgwCoreLib.BlazorTest/Data/TestData.cs
@@ -17,7 +17,8 @@ namespace EgwCoreLib.BlazorTest.Data
{"TestSvgDraw", "Test SVG draw"},
{"TestGauges", "Test Gauges"},
{"TestChart", "Test Chart.js"},
- {"TestRadzenSched", "Test Radzen Scheduler" }
+ {"TestRadzenSched", "Test Radzen Scheduler" },
+ {"TestHwInfo", "Test HW Info" }
};
}
}
diff --git a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj
index 794fdad..8ce552e 100644
--- a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj
+++ b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj
@@ -20,6 +20,9 @@
+
+
+
diff --git a/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor b/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor
new file mode 100644
index 0000000..8151ff6
--- /dev/null
+++ b/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor
@@ -0,0 +1,119 @@
+@page "/TestHwInfo"
+@using DeviceId
+@using EgwCoreLib.Utils
+
+
+
+
+
+ -
+ Device ID
+
+ @if (ListDevId != null && ListDevId.Count > 0)
+ {
+ @foreach (var item in ListDevId)
+ {
+ -
+
@item.Key
+ @item.Value
+
+ }
+ }
+
+
+
+
+ -
+ Sublicense
+
+ -
+
CodImpiego
+ @codImpiego
+
+ -
+
AppKey
+ @appKey
+
+ -
+
+
+
+
+
+
+ -
+ Machine Info
+
+ @if (ListMachineInfo != null && ListMachineInfo.Count > 0)
+ {
+ @foreach (var item in ListMachineInfo)
+ {
+ -
+
@item.Key
+ @item.Value
+
+ }
+ }
+
+
+
+
+
+@code {
+ protected Dictionary ListDevId { get; set; } = new Dictionary();
+ protected Dictionary ListMachineInfo { get; set; } = new Dictionary();
+
+ protected MachineDataValidator MDValidator { get; set; } = new MachineDataValidator();
+
+ protected SubLicManager SubLicManager { get; set; } = new SubLicManager();
+
+ protected string codImpiego = "";
+ protected string appKey = "";
+
+ protected override void OnInitialized()
+ {
+ string deviceId = "";
+ deviceId = new DeviceIdBuilder()
+ .OnWindows(windows => windows.AddWindowsDeviceId())
+ .ToString();
+ ListDevId.Add("DevId_01", deviceId);
+
+ deviceId = new DeviceIdBuilder()
+ .AddMachineName()
+ .AddOsVersion()
+ // .AddFileToken("machine.uid")
+ .ToString();
+ ListDevId.Add("DevId_02", deviceId);
+
+ deviceId = new DeviceIdBuilder()
+ .AddMachineName()
+ .AddUserName()
+ .AddOsVersion()
+ .OnWindows(windows => windows
+ .AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
+ .AddProcessorId()
+ .AddMotherboardSerialNumber()
+ .AddSystemDriveSerialNumber())
+ .ToString();
+ ListDevId.Add("DevId_03", deviceId);
+
+ ListMachineInfo = MachineDataValidator.userInfo;
+ foreach (var item in MachineDataValidator.netInfo)
+ {
+ if (!ListMachineInfo.ContainsKey(item.Key))
+ {
+ ListMachineInfo.Add(item.Key, item.Value);
+ }
+ }
+
+ Regenerate();
+ }
+
+ protected void Regenerate()
+ {
+ codImpiego = SubLicManager.CodImpiego();
+ appKey = SubLicManager.GenKey(passphrase);
+ }
+
+ private string passphrase = "SaltPass";
+}
\ No newline at end of file
diff --git a/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj b/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj
index f74f863..93cd269 100644
--- a/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj
+++ b/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj
@@ -5,8 +5,8 @@
enable
enable
EgwCoreLib.Razor
- 0.9.0.0
- S.E. Locatelli, Z.Majid
+ 1.5.0.0
+ S.E. Locatelli
EgalWare
Libreria componenti Razor/Blazor
false
diff --git a/EgwCoreLib.Utils/EgwCoreLib.Utils.csproj b/EgwCoreLib.Utils/EgwCoreLib.Utils.csproj
index bd19ffe..ad2e315 100644
--- a/EgwCoreLib.Utils/EgwCoreLib.Utils.csproj
+++ b/EgwCoreLib.Utils/EgwCoreLib.Utils.csproj
@@ -5,7 +5,7 @@
enable
enable
EgwCoreLib.Utils
- 0.9.0.0
+ 1.5.0.0
S.E. Locatelli
EgalWare
Libreria Utility base dotnet core
@@ -16,7 +16,12 @@
+
+
+
+
+
diff --git a/EgwCoreLib.Utils/MachineDataValidator.cs b/EgwCoreLib.Utils/MachineDataValidator.cs
new file mode 100644
index 0000000..7bad3b1
--- /dev/null
+++ b/EgwCoreLib.Utils/MachineDataValidator.cs
@@ -0,0 +1,219 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EgwCoreLib.Utils
+{
+ ///
+ /// Classe validazione valori
+ ///
+ public class MachineDataValidator
+ {
+ #region Public Fields
+
+ public static Dictionary biosInfo = new Dictionary();
+
+ public static Dictionary cpuInfo = new Dictionary();
+
+ public static Dictionary netInfo = new Dictionary();
+
+ public static Dictionary osInfo = new Dictionary();
+
+ public static Dictionary ramInfo = new Dictionary();
+
+ public static Dictionary userInfo = new Dictionary();
+
+ public static Dictionary volInfo = new Dictionary();
+
+ #endregion Public Fields
+
+ #region Public Constructors
+
+ ///
+ /// Init classe validatore
+ ///
+ ///
+ public MachineDataValidator()
+ {
+ // inizializzo info di base
+ if (machTestData == null || machTestData.Count == 0)
+ {
+ machTestData = setupData();
+ }
+ }
+
+ #endregion Public Constructors
+
+ #region Public Properties
+
+ ///
+ /// Restituisce HASH del codice impiego = payload utente
+ ///
+ ///
+ public string macHash
+ {
+ get => calcMachineHash();
+ }
+
+ #endregion Public Properties
+
+#if false
+ ///
+ /// Verifica validità info correnti
+ ///
+ ///
+ public async Task testCurrInfo()
+ {
+ return await testInfo();
+ }
+#endif
+
+ #region Public Methods
+
+ ///
+ /// Verifica validità info correnti
+ ///
+ ///
+ public static async Task testCurrInfo()
+ {
+ var cDV = new MachineDataValidator();
+ return await cDV.testInfo();
+ }
+
+ #endregion Public Methods
+
+ #region Private Fields
+
+ ///
+ /// Dati rispetto cui fare i calcoli di validazione
+ ///
+ private static Dictionary machTestData = new Dictionary();
+
+ #endregion Private Fields
+
+ #region Private Methods
+
+ ///
+ /// Calcola HASH del codice impiego = payload utente
+ ///
+ ///
+ private string calcMachineHash()
+ {
+ string hash = "";
+ string buffData = currBaseBuffer();
+ if (!string.IsNullOrEmpty(buffData))
+ {
+ // hashing!
+
+ using (var hAlgo = SHA512.Create())
+ //using (var hAlgo = MD5.Create())
+ {
+ byte[] InputBytes = Encoding.UTF8.GetBytes(buffData);
+ var byteHash = hAlgo.ComputeHash(InputBytes);
+ hash = BitConverter.ToString(byteHash).Replace("-", "").Replace("/", "").Replace("\\", "").ToLowerInvariant();
+ }
+ }
+ return hash;
+ }
+
+ ///
+ /// Calcola hash key da info PC
+ ///
+ ///
+ private string currBaseBuffer()
+ {
+ string answ = "????????????????????????????????????????????";
+ StringBuilder sb = new StringBuilder();
+ try
+ {
+ // calcolo hashKey da alcuni valori solamente
+ sb.Append($"{machTestData["SystemName"]}|");
+ sb.Append($"{machTestData["ProcessorId"]}|");
+ sb.Append($"{machTestData["PartNumber"]}|");
+ sb.Append($"{machTestData["MACAddress"]}|");
+ sb.Append($"{machTestData["SerialNumber"]}|");
+ sb.Append($"{machTestData["OSArchitecture"]}|");
+ sb.Append($"{machTestData["SoftwareElementID"]}|");
+ sb.Append($"{machTestData["SystemBiosMajorVersion"]}|");
+ sb.Append($"{machTestData["SystemBiosMinorVersion"]}|");
+ sb.Append($"{machTestData["CpuVersion"]}|");
+ sb.Append($"{machTestData["BiosVersion"]}|");
+ if (sb.Length > 0)
+ {
+ answ = sb.ToString();
+ // lo uso 2 volte dritto e reverse...
+ answ += ReverseString(sb.ToString());
+ }
+ }
+ catch
+ { }
+ return answ;
+ }
+
+ ///
+ /// Legge la hash key dal file licenza salvato
+ ///
+ ///
+ ///
+ private async Task getSavedHash()
+ {
+ string answ = "############################################################";
+ string filePath = "Conf/lic.file";
+ if (File.Exists(filePath))
+ {
+ answ = await File.ReadAllTextAsync(filePath);
+ }
+ return answ;
+ }
+
+ ///
+ /// Esegue reverse delal stringa
+ ///
+ ///
+ ///
+ private string ReverseString(string myStr)
+ {
+ char[] myArr = myStr.ToCharArray();
+ Array.Reverse(myArr);
+ return new string(myArr);
+ }
+
+ ///
+ /// Predispone elenco dati di test
+ ///
+ ///
+ private Dictionary setupData()
+ {
+ // creo un unico array di info
+ Dictionary testData = new Dictionary();
+ biosInfo = MachineInfo.GetInfo("BIOS");
+ cpuInfo = MachineInfo.GetInfo("CPU");
+ netInfo = MachineInfo.GetInfo("NET");
+ osInfo = MachineInfo.GetInfo("OS");
+ ramInfo = MachineInfo.GetInfo("RAM");
+ userInfo = MachineInfo.GetInfo("USER");
+ volInfo = MachineInfo.GetInfo("VOL");
+ testData = biosInfo.Concat(cpuInfo).Concat(netInfo).Concat(osInfo).Concat(ramInfo).GroupBy(ele => ele.Key).ToDictionary(ele => ele.Key, ele => ele.First().Value);
+ return testData;
+ }
+
+ ///
+ /// Effettua verifica putuale tra hash Key fornita ed hash key calcolata da info PC
+ ///
+ ///
+ private async Task testInfo()
+ {
+ // recupero hash key da conf applicativo (licenza)
+ string fileHash = await getSavedHash();
+ /// recupero hash calcolata
+ string calcHash = calcMachineHash();
+ // confronto con hashKey calcolata da info PC + dati...
+ return fileHash.Equals(calcHash);
+ }
+
+ #endregion Private Methods
+ }
+}
diff --git a/EgwCoreLib.Utils/MachineInfo.cs b/EgwCoreLib.Utils/MachineInfo.cs
new file mode 100644
index 0000000..e0f9bfb
--- /dev/null
+++ b/EgwCoreLib.Utils/MachineInfo.cs
@@ -0,0 +1,335 @@
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EgwCoreLib.Utils
+{
+ ///
+ /// Gestione info macchina
+ /// ATTENZIONE! per ora solo windows...
+ ///
+ public class MachineInfo
+ {
+ #region Public Methods
+
+ ///
+ /// Restitusice info richieste
+ ///
+ ///
+ ///
+ public static Dictionary GetInfo(string infoType)
+ {
+ var outInfo = new Dictionary();
+ switch (infoType)
+ {
+ case "BIOS":
+ outInfo = GetBiosInfo();
+ break;
+
+ case "CPU":
+ outInfo = GetCpuInfo();
+ break;
+
+ case "NET":
+ outInfo = GetNetInfo();
+ break;
+
+ case "OS":
+ outInfo = GetOsInfo();
+ break;
+
+ case "RAM":
+ outInfo = GetRamInfo();
+ break;
+
+ case "USER":
+ outInfo = GetUserInfo();
+ break;
+
+ case "VOL":
+ outInfo = GetVolumeInfo();
+ break;
+
+ default:
+ break;
+ }
+ return outInfo;
+ }
+
+ #endregion Public Methods
+
+ #region Private Fields
+
+ private static Logger Log = LogManager.GetCurrentClassLogger();
+
+ #endregion Private Fields
+
+ #region Private Methods
+
+ ///
+ /// Info BIOS
+ ///
+ ///
+ private static Dictionary GetBiosInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select * from Win32_BIOS").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ searchWmiParam(DictParam, obj, "Manufacturer", "Manufacturer");
+ searchWmiParam(DictParam, obj, "ReleaseDate", "ReleaseDate");
+ searchWmiParam(DictParam, obj, "SMBIOSBIOSVersion", "SMBIOSBIOSVersion");
+ searchWmiParam(DictParam, obj, "SMBIOSMajorVersion", "SMBIOSMajorVersion");
+ searchWmiParam(DictParam, obj, "SMBIOSMinorVersion", "SMBIOSMinorVersion");
+ searchWmiParam(DictParam, obj, "SoftwareElementID", "SoftwareElementID");
+ searchWmiParam(DictParam, obj, "SoftwareElementState", "SoftwareElementState");
+ searchWmiParam(DictParam, obj, "SystemBiosMajorVersion", "SystemBiosMajorVersion");
+ searchWmiParam(DictParam, obj, "SystemBiosMajorVersion", "SystemBiosMajorVersion");
+ searchWmiParam(DictParam, obj, "SystemBiosMinorVersion", "SystemBiosMinorVersion");
+ searchWmiParam(DictParam, obj, "BiosVersion", "Version");
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Info processore
+ ///
+ ///
+ private static Dictionary GetCpuInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select * from Win32_Processor").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ searchWmiParam(DictParam, obj, "AddressWidth", "AddressWidth");
+ searchWmiParam(DictParam, obj, "Architecture", "Architecture");
+ searchWmiParam(DictParam, obj, "CurrentClockSpeed", "CurrentClockSpeed");
+ searchWmiParam(DictParam, obj, "CurrentVoltage", "CurrentVoltage");
+ searchWmiParam(DictParam, obj, "DataWidth", "DataWidth");
+ searchWmiParam(DictParam, obj, "Description", "Description");
+ searchWmiParam(DictParam, obj, "ExtClock", "ExtClock");
+ searchWmiParam(DictParam, obj, "Family", "Family");
+ searchWmiParam(DictParam, obj, "L2CacheSize", "L2CacheSize");
+ searchWmiParam(DictParam, obj, "L3CacheSize", "L3CacheSize");
+ searchWmiParam(DictParam, obj, "Level", "Level");
+ searchWmiParam(DictParam, obj, "LoadPercentage", "LoadPercentage");
+ searchWmiParam(DictParam, obj, "Manufacturer", "Manufacturer");
+ searchWmiParam(DictParam, obj, "NumberOfCores", "NumberOfCores");
+ searchWmiParam(DictParam, obj, "NumberOfLogicalProcessors", "NumberOfLogicalProcessors");
+ searchWmiParam(DictParam, obj, "ProcessorId", "ProcessorId");
+ searchWmiParam(DictParam, obj, "ProcessorType", "ProcessorType");
+ searchWmiParam(DictParam, obj, "Revision", "Revision");
+ searchWmiParam(DictParam, obj, "Role", "Role");
+ searchWmiParam(DictParam, obj, "SocketDesignation", "SocketDesignation");
+ searchWmiParam(DictParam, obj, "SystemName", "SystemName");
+ searchWmiParam(DictParam, obj, "CpuVersion", "Version");
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Info Networking
+ ///
+ ///
+ private static Dictionary GetNetInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select * from Win32_NetworkAdapter WHERE NetEnabled = 'true'").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ searchWmiParam(DictParam, obj, "AdapterType", "AdapterType");
+ searchWmiParam(DictParam, obj, "Description", "Description");
+ searchWmiParam(DictParam, obj, "GUID", "GUID");
+ searchWmiParam(DictParam, obj, "MACAddress", "MACAddress");
+ searchWmiParam(DictParam, obj, "Manufacturer", "Manufacturer");
+ searchWmiParam(DictParam, obj, "Name", "Name");
+ searchWmiParam(DictParam, obj, "SystemName", "SystemName");
+ searchWmiParam(DictParam, obj, "PhysicalAdapter", "PhysicalAdapter");
+ searchWmiParam(DictParam, obj, "ProductName", "ProductName");
+ searchWmiParam(DictParam, obj, "ServiceName", "ServiceName");
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Info OS
+ ///
+ ///
+ private static Dictionary GetOsInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select * from Win32_OperatingSystem").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ searchWmiParam(DictParam, obj, "Caption", "Caption");
+ searchWmiParam(DictParam, obj, "Version", "Version");
+ searchWmiParam(DictParam, obj, "MaxNumberOfProcesses", "MaxNumberOfProcesses");
+ searchWmiParam(DictParam, obj, "MaxProcessMemorySize", "MaxProcessMemorySize");
+ searchWmiParam(DictParam, obj, "OSArchitecture", "OSArchitecture");
+ searchWmiParam(DictParam, obj, "SerialNumber", "SerialNumber");
+ searchWmiParam(DictParam, obj, "BuildNumber", "BuildNumber");
+ searchWmiParam(DictParam, obj, "RegisteredUser", "RegisteredUser");
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Info RAM
+ ///
+ ///
+ private static Dictionary GetRamInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select * from Win32_PhysicalMemory").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ searchWmiParam(DictParam, obj, "DeviceLocator", "DeviceLocator");
+ searchWmiParam(DictParam, obj, "DataWidth", "DataWidth");
+ searchWmiParam(DictParam, obj, "ConfiguredVoltage", "ConfiguredVoltage");
+ searchWmiParam(DictParam, obj, "FormFactor", "FormFactor");
+ searchWmiParam(DictParam, obj, "ConfiguredClockSpeed", "ConfiguredClockSpeed");
+ searchWmiParam(DictParam, obj, "MaxVoltage", "MaxVoltage");
+ searchWmiParam(DictParam, obj, "MinVoltage", "MinVoltage");
+ searchWmiParam(DictParam, obj, "Speed", "Speed");
+ searchWmiParam(DictParam, obj, "SMBIOSMemoryType", "SMBIOSMemoryType");
+ searchWmiParam(DictParam, obj, "PartNumber", "PartNumber");
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Info User (macchina, dominio, username)
+ ///
+ ///
+ private static Dictionary GetUserInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+ try
+ {
+ DictParam.Add("MachineName", Environment.MachineName);
+ DictParam.Add("UserDomainName", Environment.UserDomainName);
+ DictParam.Add("UserName", Environment.UserName);
+ }
+ catch(Exception exc)
+ {
+ Log.Error($"Error in GetUserInfo{Environment.NewLine}{exc}");
+ }
+
+ return DictParam;
+ }
+
+ ///
+ /// Info Volumes (HDD/SSD)
+ ///
+ ///
+ private static Dictionary GetVolumeInfo()
+ {
+ ManagementObjectCollection moc;
+ Dictionary DictParam = new Dictionary();
+
+ try
+ {
+ moc = new ManagementObjectSearcher("select DriveLetter, DeviceID from Win32_Volume").Get();
+ }
+ catch
+ {
+ Log.Error("Error: WMI API Not loaded.");
+ return DictParam;
+ }
+
+ foreach (ManagementObject obj in moc)
+ {
+ // mi limito al disco "C:"
+ string sDrive = "DriveLetter";
+ var objVal = $"{obj[sDrive]}";
+ if (objVal == "C:")
+ {
+ searchWmiParam(DictParam, obj, "DeviceID", "DeviceID");
+ searchWmiParam(DictParam, obj, "DriveLetter", "DriveLetter");
+ }
+ }
+ return DictParam;
+ }
+
+ ///
+ /// Effettua estrazione parametri WMI da elenco recuperato
+ ///
+ ///
+ ///
+ ///
+ ///
+ private static void searchWmiParam(Dictionary Processor, ManagementObject obj, string pName, string pKey)
+ {
+ try
+ {
+ var objVal = $"{obj[pKey]}";
+ string strVal = objVal != null ? objVal : "";
+ Processor.Add(pName, strVal);
+ }
+ catch
+ { }
+ }
+
+ #endregion Private Methods
+ }
+}
diff --git a/EgwCoreLib.Utils/SubLicManager.cs b/EgwCoreLib.Utils/SubLicManager.cs
new file mode 100644
index 0000000..f0c1368
--- /dev/null
+++ b/EgwCoreLib.Utils/SubLicManager.cs
@@ -0,0 +1,69 @@
+using DeviceId;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EgwCoreLib.Utils
+{
+ ///
+ /// Classe gestione SubLicenze (attivazioni)
+ ///
+ public class SubLicManager
+ {
+ private MachineDataValidator MachineDataValidator { get; set; } = null!;
+
+ private MachineInfo MachineInfo { get; set; } = null!;
+
+ public SubLicManager()
+ {
+ MachineDataValidator = new MachineDataValidator();
+ MachineInfo = new MachineInfo();
+ }
+
+ public string CodImpiego()
+ {
+ Guid tempKey = Guid.NewGuid();
+ string codice = $"{tempKey}";
+ // impiego libreria nuget
+ codice = new DeviceIdBuilder()
+ .AddMachineName()
+ .AddUserName()
+ .AddOsVersion()
+ .OnWindows(windows => windows
+ .AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true)
+ .AddProcessorId()
+ .AddMotherboardSerialNumber()
+ .AddSystemDriveSerialNumber())
+ .ToString();
+ return codice;
+ }
+ ///
+ /// Genera KEY macchina in modalità encrypt
+ ///
+ ///
+ ///
+ public string GenKey(string passphrase)
+ {
+ Guid tempKey = Guid.NewGuid();
+ string message = $"{tempKey}";
+ var UserData = MachineInfo.GetInfo("USER");
+ string payload = $"{DateTime.Now:yyMMdd}-{DateTime.Now:HHmmss}";
+ if (UserData.ContainsKey("MachineName"))
+ {
+ payload += $"|{UserData["MachineName"]}";
+ }
+ if (UserData.ContainsKey("UserDomainName"))
+ {
+ payload += $"|{UserData["UserDomainName"]}";
+ }
+ if (UserData.ContainsKey("UserName"))
+ {
+ payload += $"|{UserData["UserName"]}";
+ }
+ return SteamCrypto.EncryptString(message, passphrase);
+ }
+
+ }
+}