From 1d8d58f7ba382b004880519228416c6cdbc7c69e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 26 Sep 2024 07:50:20 +0200 Subject: [PATCH] Update metodi gen chiave --- EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor | 8 ++++- EgwCoreLib.Utils/SubLicManager.cs | 35 ++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor b/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor index 8151ff6..401fd60 100644 --- a/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor +++ b/EgwCoreLib.BlazorTest/Pages/TestHwInfo.razor @@ -30,6 +30,10 @@
CodImpiego
@codImpiego
+
  • +
    Payload
    +
    @decVal
    +
  • AppKey
    @appKey
    @@ -69,6 +73,7 @@ protected string codImpiego = ""; protected string appKey = ""; + protected string decVal = ""; protected override void OnInitialized() { @@ -112,7 +117,8 @@ protected void Regenerate() { codImpiego = SubLicManager.CodImpiego(); - appKey = SubLicManager.GenKey(passphrase); + appKey = SubLicManager.GenKey(passphrase, false); + decVal = SteamCrypto.DecryptString(appKey, passphrase); } private string passphrase = "SaltPass"; diff --git a/EgwCoreLib.Utils/SubLicManager.cs b/EgwCoreLib.Utils/SubLicManager.cs index f0c1368..57322b0 100644 --- a/EgwCoreLib.Utils/SubLicManager.cs +++ b/EgwCoreLib.Utils/SubLicManager.cs @@ -12,9 +12,7 @@ namespace EgwCoreLib.Utils /// public class SubLicManager { - private MachineDataValidator MachineDataValidator { get; set; } = null!; - - private MachineInfo MachineInfo { get; set; } = null!; + #region Public Constructors public SubLicManager() { @@ -22,6 +20,10 @@ namespace EgwCoreLib.Utils MachineInfo = new MachineInfo(); } + #endregion Public Constructors + + #region Public Methods + public string CodImpiego() { Guid tempKey = Guid.NewGuid(); @@ -39,31 +41,42 @@ namespace EgwCoreLib.Utils .ToString(); return codice; } + /// /// Genera KEY macchina in modalità encrypt /// /// + /// /// - public string GenKey(string passphrase) + public string GenKey(string passphrase, bool addGuid = false) { Guid tempKey = Guid.NewGuid(); - string message = $"{tempKey}"; var UserData = MachineInfo.GetInfo("USER"); - string payload = $"{DateTime.Now:yyMMdd}-{DateTime.Now:HHmmss}"; + string payload = addGuid ? $"|{tempKey}|" : ""; if (UserData.ContainsKey("MachineName")) { - payload += $"|{UserData["MachineName"]}"; + payload += $"{UserData["MachineName"]}|"; } if (UserData.ContainsKey("UserDomainName")) { - payload += $"|{UserData["UserDomainName"]}"; + payload += $"{UserData["UserDomainName"]}|"; } if (UserData.ContainsKey("UserName")) { - payload += $"|{UserData["UserName"]}"; + payload += $"{UserData["UserName"]}|"; } - return SteamCrypto.EncryptString(message, passphrase); + payload += $"{DateTime.Now:yyMMdd}-{DateTime.Now:HHmmss}|"; + return SteamCrypto.EncryptString(payload, passphrase); } + #endregion Public Methods + + #region Private Properties + + private MachineDataValidator MachineDataValidator { get; set; } = null!; + + private MachineInfo MachineInfo { get; set; } = null!; + + #endregion Private Properties } -} +} \ No newline at end of file