public LicenseHelper() { asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); encodingService = new EncodingService(); objectSerializationProvider = new ObjectSerializationProvider(); symmetricEncryptionProvider = new SymmetricEncryptionProvider(); clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepository); serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); keygen = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); service = new LicenseKeyService(keygen, packingService, clientLicenseService); productsProvider = new ProductsProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); zipCompressionProvider = new ZipCompressionProvider(); wcfPackagingService = new WcfPackagingService(zipCompressionProvider); //licenseSetsRepository = new LicenseSetsRepository(); //licenseSetService = new LicenseSetService(); //licenseService = new LicenseService(); License = new License(); License.Name = "UnitTest License"; License.UniqueId = Guid.NewGuid(); License.KeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); //string path = System.Reflection.Assembly.GetAssembly(typeof(LicenseHelper)).Location; string path = Helper.AssemblyDirectory; DllHash = encodingService.Encode(hashingProvider.HashFile(path + "\\WaveTech.Scutex.Licensing.dll")); PublicKey = encodingService.Encode(License.KeyPair.PublicKey); }
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 void CanPackAndUnpackToken() { NumberDataGenerator numberDataGenerator = new NumberDataGenerator(); PackingService packingService = new PackingService(numberDataGenerator); Token t = new Token(); t.Data = tokenData; t.Timestamp = DateTime.Now; string packedToken = packingService.PackToken(t); Token unpackedToken = packingService.UnpackToken(packedToken); Assert.AreEqual(tokenData, unpackedToken.Data); Assert.AreEqual(t.Timestamp.Day, unpackedToken.Timestamp.Day); Assert.AreEqual(t.Timestamp.Month, unpackedToken.Timestamp.Month); Assert.AreEqual(t.Timestamp.Year, unpackedToken.Timestamp.Year); Assert.AreEqual(t.Timestamp.Hour, unpackedToken.Timestamp.Hour); Assert.AreEqual(t.Timestamp.Minute, unpackedToken.Timestamp.Minute); }
public static void LicenseKeyGenerationTest() { 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); KeyGenerator staticKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); LicenseKeyService licenseKeyService = new LicenseKeyService(staticKeyGenerator, 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; for (int i = 0; i < 100000; i++) { string key = licenseKeyService.GenerateLicenseKey("TEST", license, generationOptions); licenseKeys.Add(key, key.GetHashCode().ToString()); Console.WriteLine(key); } DateTime end = DateTime.Now; Console.WriteLine(start - end); }
public static void HashTokenWithSalt() { HashingProvider provider = new HashingProvider(); Console.WriteLine(provider.ComputeHashWithSalt("b$7SDt%43J*a!9", "SHA256", null)); PackingService service = new PackingService(new NumberDataGenerator()); Token t = new Token(); t.Data = "MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA=="; t.Timestamp = DateTime.Now; Console.WriteLine(service.PackToken(t)); SymmetricEncryptionProvider encryption = new SymmetricEncryptionProvider(); EncryptionInfo ei = new EncryptionInfo(); ei.HashAlgorithm = "SHA1"; ei.InitVector = "a01JQ3481Ahnqwe9"; ei.Iterations = 2; ei.KeySize = 256; ei.PassPhrase = "Da*eW6_EzU4_swuk8*hU"; ei.SaltValue = "VuW9uDrE"; Console.WriteLine(encryption.Encrypt("861641072009MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==41410860", ei)); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
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("'")); } }
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); 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>(); 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(); } }