public ZLicense(string licenseKey = "") { try { if (string.IsNullOrEmpty(licenseKey)) { licenseKey = GetLicenseKey(); } LicenseKey = licenseKey; var license = Lic.Verifier .WithRsaPublicKey(PublicKey) // .WithSigner(ISigner) .WithApplicationCode(APP_CODE) // .WithoutApplicationCode .LoadAndVerify(LicenseKey); IssueDate = license.IssueDate; ExpirationDate = license.ExpirationDate; HardwareIdentifier = license.HardwareIdentifier; SerialNumber = license.SerialNumber; ZId = license.Properties["ZId"]; Username = license.Properties["Username"]; SupportedApps = license.Properties["SupportedApps"]; SupportedDevices = license.Properties["SupportedDevices"]; } catch { IssueDate = DateTime.Now; ExpirationDate = DateTime.Now; SerialNumber = SerialNo.Create(APP_CODE); HardwareIdentifier = HWId.ForCurrentComputer(); ZId = HardwareInfo.GenerateUID(); SupportedApps = ""; SupportedDevices = ""; } }
internal string VerifyLicense(string licenseText) { var errorMessage = string.Empty; try { SignedLicense license = Lic.Verifier .WithRsaPublicKey(PublicKey) // .WithSigner(ISigner) .WithApplicationCode(APP_CODE) // .WithoutApplicationCode .LoadAndVerify(licenseText); if (DateTime.Compare(license.ExpirationDate, DateTime.Now) < 0) { errorMessage = "License expired"; } else { if ((license.HardwareIdentifier != HardwareIdentifier) || (license.Properties["ZId"] != ZId) || (license.Properties["ExpirationDate"] != license.ExpirationDate.ToString(DATE_FROMAT))) { errorMessage = "Invalid license"; } if (!HWId.IsCheckSumValid(license.HardwareIdentifier)) { errorMessage = "Invalid license"; } } SupportedApps = license.Properties["SupportedApps"]; SupportedDevices = license.Properties["SupportedDevices"]; } catch (Exception ex) { if (ex.Message.StartsWith("License has been expired")) { errorMessage = ex.Message; } else { errorMessage = "Invalid license"; } } return(errorMessage); }
SignedLicense IVerifier_VerifyLoad.LoadAndVerify(string licenseString) { var license = SignedLicense.Deserialize(licenseString); // verify signature license.Verify(mySigner); // verify application code if (!SerialNumber.IsApplicationCodeValid(license.SerialNumber, myApplicationCode)) { throw new SignedLicenseException($"Application Code '{myApplicationCode}' is not valid for the license."); } // verify hardware identifier if (!HardwareIdentifier.IsValidForCurrentComputer(license.HardwareIdentifier)) { throw new SignedLicenseException($"License has been activated for another computer."); } // verify expiration date if (license.ExpirationDate < DateTime.UtcNow) { throw new SignedLicenseException($"License has been expired since '{license.ExpirationDate}'."); } return(license); }