Пример #1
0
        SignedLicense IBuilder_Properties.SignAndCreate()
        {
            var license = new SignedLicense(myHardwareIdentifier, mySerialNumber, DateTime.Now, myExpirationDate, myProperties);

            license.Sign(mySigner);
            return(license);
        }
Пример #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);
        }