using System.Security.Cryptography; using System.Text; using System.Runtime.InteropServices; namespace IronLicensing.Client; public partial class MachineIdentifier : IMachineIdentifier { public string GetMachineId() { var components = GetMachineComponents(); var combined = string.Join("|", components.Where(c => !string.IsNullOrEmpty(c))); if (string.IsNullOrEmpty(combined)) { #if MAUI // Fallback to a device-specific identifier (MAUI platforms) combined = DeviceInfo.Current.Idiom.ToString() + "|" + DeviceInfo.Current.Manufacturer + "|" + DeviceInfo.Current.Model; #else // Fallback for server/console apps combined = Environment.MachineName + "|" + Environment.UserName + "|" + RuntimeInformation.OSDescription; #endif } using var sha256 = SHA256.Create(); var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(combined)); return Convert.ToBase64String(hash)[..32]; } public string GetMachineName() { #if MAUI return DeviceInfo.Current.Name ?? Environment.MachineName ?? "Unknown"; #else return Environment.MachineName ?? "Unknown"; #endif } public string GetPlatform() { #if MAUI return DeviceInfo.Current.Platform.ToString(); #else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return "Windows"; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return "macOS"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return "Linux"; return RuntimeInformation.OSDescription; #endif } // Platform-specific implementation private partial List GetMachineComponents(); }