Example #1
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();
            IHardwareFingerprintService  hardwareFingerprintService  = new HardwareFingerprintService(new WmiDataProvider(), new HashingProvider());
            IPackingService          packingService          = new PackingService(numberDataGeneratorProvider);
            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                           symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            ILargeKeyGenerator largeKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService);
            ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            LicenseKeyService  licenseKeyService = new LicenseKeyService(smallKeyGenerator, largeKeyGenerator, 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("'"));
            }
        }
        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("'"));
            }
        }