public void LicenseKeyBatchGeneratorVerify() { List <string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); Assert.IsNotNull(keys); Assert.AreEqual(100000, keys.Count); }
public static void BatchSmallLicenseKeyGenrationTest() { 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"); DateTime start = DateTime.Now; List <string> licenseKeys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); Dictionary <string, string> doubleCheck = new Dictionary <string, string>(); DateTime end = DateTime.Now; foreach (string s in licenseKeys) { doubleCheck.Add(s, ""); Console.WriteLine(s); } Console.WriteLine(); Console.WriteLine("================================="); 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(); }
public string GenerateLicenseKey(LicenseKeyTypes keyTypes) { LicenseGenerationOptions options = new LicenseGenerationOptions(); options.LicenseKeyType = keyTypes; List <string> keys = service.GenerateLicenseKeys(License.KeyPair.PrivateKey, License, options, 1); return(keys.First()); }
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("'")); } }
private void btnGenerateKeys_Click(object sender, System.Windows.RoutedEventArgs e) { if (IsGenerationFormValid()) { loadingAnimation.Visibility = Visibility.Visible; BackgroundWorker worker = new BackgroundWorker(); LicenseGenerationOptions licenseGenerationOptions = new LicenseGenerationOptions(); int keysToGenerate = int.Parse(txtKeysToGenerate.Text); if (cboSingleUser.IsChecked.HasValue && cboSingleUser.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.SingleUser; } else if (cboMultiUser.IsChecked.HasValue && cboMultiUser.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.MultiUser; } else if (cboHardwareLock.IsChecked.HasValue && cboHardwareLock.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.HardwareLock; } else if (cboUnlimited.IsChecked.HasValue && cboUnlimited.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Unlimited; } else if (cboEnterprise.IsChecked.HasValue && cboEnterprise.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Enterprise; } else if (cboHardwareLockLocal.IsChecked.HasValue && cboHardwareLockLocal.IsChecked.Value) { licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.HardwareLockLocal; licenseGenerationOptions.HardwareFingerprint = txtHardwareKeyData.Text; keysToGenerate = 1; // Can only generate 1 local hardware locked key at a time. } licenseGenerationOptions.LicenseSetId = ((LicenseSet)cboLicenseSet.SelectedValue).LicenseSetId; worker.DoWork += delegate(object s, DoWorkEventArgs args) { object[] data = args.Argument as object[]; ISmallKeyGenerator smallKeygen = ObjectLocator.GetInstance <ISmallKeyGenerator>(); ILargeKeyGenerator largeKeygen = ObjectLocator.GetInstance <ILargeKeyGenerator>(); ILicenseActiviationProvider licenseActiviationProvider = ObjectLocator.GetInstance <ILicenseActiviationProvider>(); IPackingService packingService = ObjectLocator.GetInstance <IPackingService>(); IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>(); if ((string)data[2] == InstanceNames.SmallKeyGenerator) { ((LicenseGenerationOptions)data[0]).GeneratorType = KeyGeneratorTypes.StaticSmall; } else { ((LicenseGenerationOptions)data[0]).GeneratorType = KeyGeneratorTypes.StaticLarge; } LicenseKeyService service = new LicenseKeyService(smallKeygen, largeKeygen, packingService, clientLicenseService); List <string> keys = service.GenerateLicenseKeys(UIContext.License.KeyPair.PrivateKey, UIContext.License, (LicenseGenerationOptions)data[0], int.Parse(data[1].ToString())); args.Result = keys; }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { LicenseKeys = new BindingList <string>((List <string>)args.Result); lstLicenseKeys.ItemsSource = LicenseKeys; loadingAnimation.Visibility = Visibility.Collapsed; }; worker.RunWorkerAsync(new object[] { licenseGenerationOptions, keysToGenerate, GetGeneratorName() }); } else { MessageBox.Show("Please select a license set, license type to generate and a amount."); } }