Exemplo n.º 1
0
        private static LicenseTerms ValidateLicense(LicenseDTO license)
        {
            RSACryptoServiceProvider rsa = GetPublicKeyFromAssemblyAtClient(Assembly.GetExecutingAssembly());

            byte[] dataToVerify = Convert.FromBase64String(license.LicenseTerms);
            byte[] signature    = Convert.FromBase64String(license.Signature);

            // verify that the license-terms match the signature data
            if (rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signature))
            {
                return(LicenseTerms.FromString(license.LicenseTerms));
            }
            else
            {
                throw new Exception("license file is tempered.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// validate license file and return the license terms.
        /// </summary>
        /// <param name="license"></param>
        /// <param name="publicKey"></param>
        /// <returns></returns>
        internal static LicenseTerms GetValidTerms(License license, String publicKey)
        {
            // create the crypto-service provider:
            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();

            // setup the provider from the public key:
            dsa.FromXmlString(publicKey);

            // get the license terms data:
            byte[] terms = Convert.FromBase64String(license.LicenseTerms);

            // get the signature data:
            byte[] signature = Convert.FromBase64String(license.Signature);

            // verify that the license-terms match the signature data
            if (dsa.VerifyData(terms, signature))
            {
                return(LicenseTerms.FromString(license.LicenseTerms));
            }
            else
            {
                throw new SecurityException("Signature Not Verified!");
            }
        }