Esempio n. 1
0
        /// <summary>
        /// Returns true if the current license permits use.
        /// </summary>
        /// <returns></returns>
        private bool CheckLicense()
        {
            //Console.WriteLine("License={0} (length={1})", license.License, license.License.Length);
            if (license.License == null || license.License.Length == 0)
            {
                if (!licenseNullMessageThrown)
                {
                    licenseNullMessageThrown = true;
                    Console.WriteLine("{0} License Manager: No valid Product Key found.", productName);
                }
                return(false);
            }

            //Create byte arrays to hold id and signature.
            UnicodeEncoding ByteConverter = new UnicodeEncoding();

            byte[] hid = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, ByteConverter.GetBytes(license.HardwareId));
            byte[] lic;
            try
            {
                lic = Convert.FromBase64String(license.License);
            }
            catch (FormatException)
            {
                Console.WriteLine("{0} License Manager: Error interpreting Product Key. Contact [email protected]", productName);
                Console.WriteLine("{0} License Manager: HID: \"{1}\"", productName, license.HardwareId);
                return(false);
            }

            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                // Read the public key from the file.
                //StreamReader sr = File.OpenText("keypair.xml");
                //string xmlString = sr.ReadToEnd();
                //sr.Close();

                RSA.FromXmlString(Resource1.String1);

                bool isValid = RSA.VerifyData(hid, "sha1", lic);
                //bool isValid = RSA.VerifyData(hid, null, lic);

                RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, "Software/The Complot/" + productName);
                if (isValid)
                {
                    // Save the new valid license in the registry.
                    if (!regedit.Write("License", license.License))
                    {
                        Console.WriteLine("{0} License Manager: Error saving your license, you might need to enter it again the next time. Contact [email protected]", productName);
                    }
                }
                else
                {
                    Console.WriteLine("{0} License Manager: The entered Product Key is not valid.", productName);
                }
                return(isValid);
            }
        }
Esempio n. 2
0
        internal override bool TryReadValue(out long value)
        {
            RegistryEditor regedit     = new RegistryEditor(Registry.CurrentUser, path);
            String         valueString = regedit.Read(Key);

            // Check if the registry contains good data.
            if (valueString != null && long.TryParse(valueString, out value))
            {
                return(true);
            }

            value = 0;
            return(false);
        }
Esempio n. 3
0
        internal override bool TryReadValue(out long value)
        {
            RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, path);
            String valueString = regedit.Read(Key);

            // Check if the registry contains good data.
            if (valueString != null && long.TryParse(valueString, out value))
            {
                return true;
            }

            value = 0;
            return false;
        }
Esempio n. 4
0
        }                                                                                   // Is trial

        public GraphicsDeviceManager(String productName)
        {
            this.productName = productName;

            // Initialize the current license status.
            license            = new GraphicsDevice(productName);
            license.HardwareId = FindHardwareId();
            RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, "Software/The Complot/" + productName);

            license.License     = regedit.Read("License");
            license.TimeEnabled = false;

            // Listen for when the license becomes valid.
            license.LicenseStatusChanged += new EventHandler(license_LicenseStatusChanged);

            // No license written yet?
            if (license.License == null)
            {
                license.License = String.Empty;
            }
            CheckLicense();
        }
Esempio n. 5
0
        /// <summary>
        /// Returns true if the current license permits use.
        /// </summary>
        /// <returns></returns>
        private bool CheckLicense()
        {
            //Console.WriteLine("License={0} (length={1})", license.License, license.License.Length);
            if (license.License == null || license.License.Length == 0)
            {
                if (!licenseNullMessageThrown)
                {
                    licenseNullMessageThrown = true;
                    Console.WriteLine("{0} License Manager: No valid Product Key found.", productName);
                }
                return false;
            }

            //Create byte arrays to hold id and signature.
            UnicodeEncoding ByteConverter = new UnicodeEncoding();
            byte[] hid = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, ByteConverter.GetBytes(license.HardwareId));
            byte[] lic;
            try
            {
                lic = Convert.FromBase64String(license.License);
            }
            catch (FormatException)
            {
                Console.WriteLine("{0} License Manager: Error interpreting Product Key. Contact [email protected]", productName);
                Console.WriteLine("{0} License Manager: HID: \"{1}\"", productName, license.HardwareId);
                return false;
            }

            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                // Read the public key from the file.
                //StreamReader sr = File.OpenText("keypair.xml");
                //string xmlString = sr.ReadToEnd();
                //sr.Close();

                RSA.FromXmlString(Resource1.String1);

                bool isValid = RSA.VerifyData(hid, "sha1", lic);
                //bool isValid = RSA.VerifyData(hid, null, lic);

                RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, "Software/The Complot/" + productName);
                if (isValid)
                {
                    // Save the new valid license in the registry.
                    if (!regedit.Write("License", license.License))
                        Console.WriteLine("{0} License Manager: Error saving your license, you might need to enter it again the next time. Contact [email protected]", productName);
                }
                else
                {
                    Console.WriteLine("{0} License Manager: The entered Product Key is not valid.", productName);
                }
                return isValid;
            }
        }
Esempio n. 6
0
        public GraphicsDeviceManager(String productName)
        {
            this.productName = productName;

            // Initialize the current license status.
            license = new GraphicsDevice(productName);
            license.HardwareId = FindHardwareId();
            RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, "Software/The Complot/" + productName);
            license.License = regedit.Read("License");
            license.TimeEnabled = false;

            // Listen for when the license becomes valid.
            license.LicenseStatusChanged += new EventHandler(license_LicenseStatusChanged);

            // No license written yet?
            if (license.License == null)
            {
                license.License = String.Empty;
            }
            CheckLicense();
        }
Esempio n. 7
0
        internal override bool HasBeenWrittenBefore()
        {
            RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, path);

            return(regedit.Read(Key) != null);
        }
Esempio n. 8
0
        internal override bool TryWriteValue(long value)
        {
            RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, path);

            return(regedit.Write(Key, value.ToString()));
        }
Esempio n. 9
0
 internal override bool TryWriteValue(long value)
 {
     RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, path);
     return regedit.Write(Key, value.ToString());
 }
Esempio n. 10
0
 internal override bool HasBeenWrittenBefore()
 {
     RegistryEditor regedit = new RegistryEditor(Registry.CurrentUser, path);
     return regedit.Read(Key) != null;
 }