Пример #1
0
        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 = "";
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
 IVerifier_VerifyLoad IVerifier_ApplicationCode.WithApplicationCode(string threeLetterApplicationCode)
 {
     myApplicationCode = SerialNumber.EnsureApplicationCodeIsValid(threeLetterApplicationCode);
     return(this);
 }