Ejemplo n.º 1
0
        /// <summary>Gets <see cref="License" /> from <see cref="LicensePublisher" /> using specified culture.</summary>
        /// <param name="cultureInfo">The specified culture information.</param>
        /// <param name="product">The product name.</param>
        /// <param name="version">The product version.</param>
        /// <param name="licenseKey">The license key.</param>
        /// <param name="category">The license category.</param>
        /// <param name="name">The user name.</param>
        /// <param name="company">The user company.</param>
        /// <param name="email">The user email address.</param>
        /// <param name="data">The data to set in the license.</param>
        /// <returns>The response from <see cref="LicensePublisher" /> which encapsulates a <see cref="License" /> object or
        /// an error message.</returns>
        public LicensePublisherResponse GetLicense(CultureInfo cultureInfo, string product, Version version, LicenseKey licenseKey, string category, string name, string company, string email, string data)
        {
            string encryptedResponse = base.Channel.Publish(cultureInfo.LCID, product, version.ToString(), licenseKey.EncryptToString(PublicKey), category, name, company, email, data);
            string response          = licenseKey.Decrypt(encryptedResponse);

            if (response.StartsWith(ErrorHeader, StringComparison.Ordinal))
            {
                string errorMessage = response.Substring(ErrorHeader.Length, response.Length - ErrorHeader.Length);
                return(new LicensePublisherResponse(errorMessage));
            }
            else
            {
                return(new LicensePublisherResponse(LicenseManager.VerifySignedLicense(PublicKey, response)));
            }
        }
Ejemplo n.º 2
0
        private License LoadLicense(string license, object providerData)
        {
            if (string.IsNullOrEmpty(license))
            {
                return(null);
            }

            Assembly assembly     = Assembly;
            string   publicKeyXml = PublicKeyXmlFromAssembly(assembly);

            if (string.IsNullOrEmpty(publicKeyXml))
            {
                throw new InvalidOperationException(ExceptionMessages.FormatNullPublicKey(assembly));
            }
            using (Rsa publicKey = new Rsa(publicKeyXml))
            {
                License result = (License)LicenseManager.VerifySignedLicense(publicKey, license);
                result.ProviderData = providerData;
                return(result);
            }
        }