public string Generate(Licence licence, string serial)
        {
            var licencePack = new LicencePack
            {
                Licence = licence,
                Serial  = serial
            };

            string licencePackString = _objectHelper.Serialize <LicencePack>(licencePack);

            return(_encryptionHelper.Encrypt(licencePackString));
        }
Esempio n. 2
0
        public Licence CheckLicence(string licencePackCipher)
        {
            string      licencePackString = "";
            string      licenceSerial     = "";
            LicencePack licencePack       = null;

            try
            {
                licencePackString = _encryptionHelper.Decrypt(licencePackCipher);
                licencePack       = _objectHelper.Deserialize <LicencePack>(licencePackString);
                licenceSerial     = _serialGenerator.Generate();
            }
            catch (Exception ex)
            {
                throw new InvalidLicenceException("Licence is not valid", ex);
            }
            if (licencePack.Serial != licenceSerial)
            {
                throw new InvalidLicenceException("Licence is not valid");
            }
            return(licencePack.Licence);
        }