示例#1
0
        public static void SmallLicenseKeyGenrationTest()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);
            IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider);

            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService);
            LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();
            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;
            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            Dictionary<string, string> licenseKeys = new Dictionary<string, string>();

            DateTime start = DateTime.Now;
            try
            {
                List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000);

                foreach (string key in keys)
                {
                    string hash = hashingProvider.ComputeHash(key, "SHA256");
                    licenseKeys.Add(hash, key);
                    Console.WriteLine(key);

                    Console.WriteLine(hash + " " + hash.Equals(hashingProvider.ComputeHash(key, "SHA256")));
                }
            }
            catch (Exception ex)
            { Console.WriteLine(ex.Message); }
            finally
            {

                Console.WriteLine();
                Console.WriteLine("=================================");

                DateTime end = DateTime.Now;
                Console.WriteLine(string.Format("Key Generation took {0}", end - start));

                Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count));

                Console.WriteLine();
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();
            }
        }
示例#2
0
        public void TestLicenseKeyHashing()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);
            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            IKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();
            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;
            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            Dictionary<string, string> licenseKeys = new Dictionary<string, string>();
            List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000);

            foreach (string key in keys)
            {
                string hash = hashingProvider.ComputeHash(key, "SHA256");
                licenseKeys.Add(hash, key);
                Console.WriteLine(key + "\t" + hash);

                Assert.IsTrue(hash.Equals(hashingProvider.ComputeHash(key, "SHA256")));
                Assert.IsFalse(hash.Contains("'"));
            }
        }