Exemple #1
0
        public void ValidateProductKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            keyPublisher = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);

            var shaHasher     = new SHA1CryptoServiceProvider();
            var usernameHash  = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("toto")));
            var companyHash   = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("Company")));
            var userEmailHash = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("*****@*****.**")));

            Assert.AreEqual(123, result.ProductID);
            Assert.AreEqual(456, result.ProductFeatures);
            Assert.AreEqual(789, result.TrialDays);
            Assert.AreEqual(usernameHash, result.UsernameHash);
            Assert.AreEqual(companyHash, result.CompanyHash);
            Assert.AreEqual(userEmailHash, result.UserEmailHash);
            Assert.AreEqual(DateTime.Now.Date, result.GeneratedDate.Date);
        }
Exemple #2
0
        public void TryValidateWithPublicKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            privateXmlKey = KeyHelpers.GetPublicKey();
            keyPublisher  = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }
Exemple #3
0
        public void TryValidateWithFakeCryptProvider()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            privateXmlKey = (new RSACryptoServiceProvider()).ToXmlString(true);
            keyPublisher  = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }
Exemple #4
0
        public void ValidateFakeProductKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);
            productKey = productKey.Replace('1', '8');
            productKey = productKey.Replace('2', '7');
            productKey = productKey.Replace('3', '6');
            productKey = productKey.Replace('4', '5');
            Console.WriteLine(productKey);

            keyPublisher = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }