// The CLR invokes this when instantiating a licensed COM // object inside a designtime license context. // It's purpose is to save away the license key that the CLR // retrieved using RequestLicKey(). This license key can be NULL. private void SaveKeyInCurrentContext(IntPtr bstrKey) { if (bstrKey != (IntPtr)0) { _savedLicenseContext.SetSavedLicenseKey(_savedType, Marshal.PtrToStringBSTR(bstrKey)); } }
/// <summary> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </summary> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense lic = null; Debug.Assert(context != null, "No context provided!"); if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { lic = new LicFileLicense(this, key); } } if (lic == null) { string modulePath = null; if (context != null) { ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolver != null) { modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName()); } } if (modulePath == null) { modulePath = type.Module.FullyQualifiedName; } string moduleDir = Path.GetDirectoryName(modulePath); string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine($"Looking for license in: {licenseFile}"); if (File.Exists(licenseFile)) { Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); if (IsKeyValid(s, type)) { lic = new LicFileLicense(this, GetKey(type)); } } if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return(lic); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense license = null; if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string savedLicenseKey = context.GetSavedLicenseKey(type, null); if ((savedLicenseKey != null) && this.IsKeyValid(savedLicenseKey, type)) { license = new LicFileLicense(this, savedLicenseKey); } } if (license != null) { return(license); } string path = null; if (context != null) { ITypeResolutionService service = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (service != null) { path = service.GetPathOfAssembly(type.Assembly.GetName()); } } if (path == null) { path = type.Module.FullyQualifiedName; } string str4 = Path.GetDirectoryName(path) + @"\" + type.FullName + ".lic"; if (File.Exists(str4)) { Stream stream = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader reader = new StreamReader(stream); string key = reader.ReadLine(); reader.Close(); if (this.IsKeyValid(key, type)) { license = new LicFileLicense(this, this.GetKey(type)); } } if (license != null) { context.SetSavedLicenseKey(type, license.LicenseKey); } } return(license); }
// Get the license for a type. public override License GetLicense (LicenseContext context, Type type, object instance, bool allowExceptions) { String key, path; StreamReader reader; // Bail out if we don't have a license context. if(context == null) { return null; } // Use the saved key if we saw this type previously. if(context.UsageMode == LicenseUsageMode.Runtime) { key = context.GetSavedLicenseKey(type, null); if(key != null && IsKeyValid(key, type)) { return new FileLicense(key); } } // Find the pathname of the assembly containing the type. #if CONFIG_COMPONENT_MODEL_DESIGN ITypeResolutionService trs; trs = (ITypeResolutionService) context.GetService(typeof(ITypeResolutionService)); if(trs != null) { path = trs.GetPathOfAssembly(type.Assembly.GetName()); if(path == null) { path = type.Assembly.Location; } } else #endif { path = type.Assembly.Location; } // Look for a "*.lic" file for the type. path = Path.Combine(Path.GetDirectoryName(path), type.FullName + ".lic"); try { reader = new StreamReader(path); } catch(Exception) { // Could not open the file, so assume unlicensed. return null; } // Read the key from the first line of the license file. key = reader.ReadLine(); reader.Close(); // Bail out if the key is invalid. if(key == null || !IsKeyValid(key, type)) { return null; } // Cache the key within the context. context.SetSavedLicenseKey(type, key); // Return a new file license to the caller. return new FileLicense(key); }
/// <summary> /// Extract the license for the given type from the given licenseKey /// </summary> /// <param name="context">The current licensing context</param> /// <param name="type">The type to be licensed</param> /// <param name="licenseKey">The encrypted hexadecimal license key</param> /// <returns>A license for the given type or NULL if the licenseKey was invalid</returns> private EncryptedLicense LoadLicense(LicenseContext context, Type type, string licenseKey) { // check that validation parameters have been set by the client // if (_rsaParameters == null || _designSignature == null || _runtimeSignature == null) throw new InvalidOperationException("EncryptedLicenseProvider.SetParameters must be called prior to using the EncryptedLicenseProvider"); if (licenseKey == null) return null; try { byte[] encData = FromHex(licenseKey); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Key = _desKey; des.IV = _desIV; byte[] data = des.CreateDecryptor().TransformFinalBlock(encData, 0, encData.Length); // extract the encryption key and encrypted product data - note that the encryption // key has only 7 significant bytes // byte[] encryptionKey = new byte[ArraySize(8)]; byte[] encPayload = new byte[ArraySize(data.Length - keyLength)]; Array.Copy(data, 0, encryptionKey, 0, keyLength); Array.Copy(data, keyLength, encPayload, 0, encPayload.Length); // validate that the password matches what the client is expecting // RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(_rsaParameters); if (context.UsageMode == LicenseUsageMode.Designtime) { // if design time license requested then the license MUST be a design license // if (!rsa.VerifyData(encryptionKey, new SHA1CryptoServiceProvider(), _designSignature)) return null; } else { // if runtime license requested then first check if the license is a runtime license // also allow design licenses to work at runtime // if (!rsa.VerifyData(encryptionKey, new SHA1CryptoServiceProvider(), _runtimeSignature)) { if (!rsa.VerifyData(encryptionKey, new SHA1CryptoServiceProvider(), _designSignature)) return null; } } // decrypt the payload using the encryption key // des.IV = encryptionKey; byte[] payload = des.CreateDecryptor().TransformFinalBlock(encPayload, 0, encPayload.Length); byte[] productData = new byte[ArraySize(payload.Length - 2)]; Array.Copy(payload, 2, productData, 0, productData.Length); UInt16 serialNo = BitConverter.ToUInt16(payload, 0); string product = System.Text.ASCIIEncoding.UTF8.GetString(productData); // if in design time then create a runtime license and save it // if (context.UsageMode == LicenseUsageMode.Designtime && type != null) { // create the runtime password by encrypting the design time license // byte[] encKey = des.CreateEncryptor().TransformFinalBlock(encryptionKey, 0, encryptionKey.Length); byte[] runtimeKey = new byte[ArraySize(8)]; Array.Copy(encKey, 0, runtimeKey, 0, keyLength); // encrypt the payload using the runtime key // des.IV = runtimeKey; encPayload = des.CreateEncryptor().TransformFinalBlock(payload, 0, payload.Length); // Combine the runtime key and encrypted payload // Note that only the first 7 bytes of the key contain information so we // only pack this much information - this enables us to reduce the size of // the final key by 8 bytes. // data = new byte[ArraySize(keyLength + encPayload.Length)]; runtimeKey.CopyTo(data, 0); encPayload.CopyTo(data, keyLength); // encrypt again to obscure the password - this time using preset encryption key // des.IV = _desIV; encData = des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length); string runtimeLicenseKey = ToHex(encData); // save the runtime key into the context // context.SetSavedLicenseKey(type, runtimeLicenseKey); } return new EncryptedLicense(licenseKey, serialNo, product); } catch { return null; } }
// Get the license for a type. public override License GetLicense (LicenseContext context, Type type, object instance, bool allowExceptions) { String key, path; StreamReader reader; // Bail out if we don't have a license context. if (context == null) { return(null); } // Use the saved key if we saw this type previously. if (context.UsageMode == LicenseUsageMode.Runtime) { key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { return(new FileLicense(key)); } } // Find the pathname of the assembly containing the type. #if CONFIG_COMPONENT_MODEL_DESIGN ITypeResolutionService trs; trs = (ITypeResolutionService) context.GetService(typeof(ITypeResolutionService)); if (trs != null) { path = trs.GetPathOfAssembly(type.Assembly.GetName()); if (path == null) { path = type.Assembly.Location; } } else #endif { path = type.Assembly.Location; } // Look for a "*.lic" file for the type. path = Path.Combine(Path.GetDirectoryName(path), type.FullName + ".lic"); try { reader = new StreamReader(path); } catch (Exception) { // Could not open the file, so assume unlicensed. return(null); } // Read the key from the first line of the license file. key = reader.ReadLine(); reader.Close(); // Bail out if the key is invalid. if (key == null || !IsKeyValid(key, type)) { return(null); } // Cache the key within the context. context.SetSavedLicenseKey(type, key); // Return a new file license to the caller. return(new FileLicense(key)); }
/// <include file='doc\LicFileLicenseProvider.uex' path='docs/doc[@for="LicFileLicenseProvider.GetLicense"]/*' /> /// <devdoc> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </devdoc> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense lic = null; Debug.Assert(context != null, "No context provided!"); if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { lic = new LicFileLicense(this, key); } } if (lic == null) { string modulePath = null; if (context != null) { ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolver != null) { modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName()); } } if (modulePath == null) { modulePath = type.Module.FullyQualifiedName; } string moduleDir = Path.GetDirectoryName(modulePath); string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine("Looking for license in: " + licenseFile); if (File.Exists(licenseFile)) { Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); if (IsKeyValid(s, type)) { lic = new LicFileLicense(this, GetKey(type)); } } if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return lic; }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { int num2; string[] textArray1; string text1 = "\nEnvironment info:\n"; text1 = text1 + "version: " + DiagramView.VersionName + "\n"; if (Assembly.GetEntryAssembly() != null) { text1 = text1 + "entry: "; try { text1 = text1 + Assembly.GetEntryAssembly().FullName; } catch (SecurityException) { text1 = text1 + "?fn?"; } object obj1 = null; try { obj1 = Assembly.GetEntryAssembly().EntryPoint; } catch (SecurityException) { text1 = text1 + "?ep?"; } if (obj1 != null) { text1 = text1 + ", has entry point\n"; } else { text1 = text1 + ", no entry point\n"; } } else { text1 = text1 + "null entry\n"; } int num1 = 0; string text2 = ""; try { try { text2 = context.GetSavedLicenseKey(type, null); } catch (SecurityException exception1) { text2 = null; text1 = text1 + "\n" + exception1.ToString(); } if (text2 != null) { text1 = text1 + "key: " + text2 + "\n"; } else { text1 = text1 + "null key\n"; } if ((text2 != null) && (text2.Length != 0)) { goto Label_01AF; } try { Assembly[] assemblyArray1 = AppDomain.CurrentDomain.GetAssemblies(); Assembly[] assemblyArray2 = assemblyArray1; for (num2 = 0; num2 < assemblyArray2.Length; num2++) { Assembly assembly1 = assemblyArray2[num2]; text1 = text1 + assembly1.FullName + "\n"; try { text2 = context.GetSavedLicenseKey(type, assembly1); } catch (SecurityException) { text2 = null; } if ((text2 != null) && (text2.Length > 0)) { goto Label_015A; } } } catch (SecurityException) { } Label_015A: text1 = text1 + DiagramView.myVersionName + "\n"; if (DiagramView.myVersionAssembly != null) { text1 = text1 + DiagramView.myVersionAssembly.GetName().Name + "\n"; } else { text1 = text1 + "null licensed assembly\n"; } if (DiagramView.myVersionName.Length > 0x18) { text2 = DiagramView.myVersionName; } Label_01AF: if ((text2 != null) && (text2.Length > 0)) { num1 = this.Dispose(text2, true); if (num1 == 4) { return new DiagramViewLicense(text2, num1); } } else { text2 = ""; RegistryKey key1 = null; try { key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Northwoods Software\Go.NET"); } catch (SecurityException exception2) { text1 = text1 + "\n" + exception2.ToString(); } if (key1 == null) { try { key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Northwoods Software\GoDiagram"); } catch (SecurityException) { } } if (key1 != null) { string text3 = type.Assembly.GetName().Name; object obj2 = null; try { obj2 = key1.GetValue(text3); } catch (SecurityException) { } if ((obj2 != null) && (obj2 is byte[])) { text2 = Convert.ToBase64String((byte[])obj2); } } num1 = this.Dispose(text2, false); if ((num1 == 0) && (key1 != null)) { text2 = ""; string text4 = type.Assembly.GetName().Name + " eval"; object obj3 = null; try { obj3 = key1.GetValue(text4); } catch (SecurityException) { } if ((obj3 != null) && (obj3 is byte[])) { text2 = Convert.ToBase64String((byte[])obj3); } num1 = this.Dispose(text2, false); } if ((num1 >= 4) && (context.UsageMode == LicenseUsageMode.Designtime)) { context.SetSavedLicenseKey(type, text2); } if ((num1 == 4) || (context.UsageMode == LicenseUsageMode.Designtime)) { return new DiagramViewLicense(text2, num1); } } } catch (Exception exception3) { text1 = text1 + "\n" + exception3.ToString(); } num2 = num1 & 3; switch (num2) { case 1: { string text7 = (num1 > 4) ? "beta" : "evaluation"; textArray1 = new string[0x10] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "This ", text7, " copy of ", DiagramViewLicenseProvider.GONAME, " is about to expire.", Environment.NewLine, Environment.NewLine, "DO NOT DISTRIBUTE OR DEPLOY THIS SOFTWARE.", Environment.NewLine }; string text8 = string.Concat(textArray1); if (num1 < 4) { text8 = text8 + Environment.NewLine + "Please purchase a license at www.nwoods.com" + Environment.NewLine; } if (SystemInformation.UserInteractive) { MessageBox.Show(text8, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text8); } return new DiagramViewLicense(text8, num1); } case 2: { string text5 = (num1 > 4) ? "beta" : "evaluation"; textArray1 = new string[14] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "This software is licensed for a limited ", text5, " period.", Environment.NewLine, Environment.NewLine, "DO NOT DISTRIBUTE OR DEPLOY THIS SOFTWARE.", Environment.NewLine }; string text6 = string.Concat(textArray1); if (num1 < 4) { text6 = text6 + Environment.NewLine + "Please purchase a license at www.nwoods.com" + Environment.NewLine; } if (SystemInformation.UserInteractive) { if (!DiagramViewLicenseProvider.err) { DiagramViewLicenseProvider.err = true; MessageBox.Show(text6, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text6); } return new DiagramViewLicense(text6, num1); } } textArray1 = new string[0x1c] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "The license for this copy of ", DiagramViewLicenseProvider.GONAME, " is invalid or has expired.", Environment.NewLine, Environment.NewLine, "Please purchase a license at www.nwoods.com", Environment.NewLine, "If you have already purchased a ", DiagramViewLicenseProvider.GONAME, " development license,", Environment.NewLine, " have you requested an Unlock Code for your development machine by running the GoDiagram LicenseManager?", Environment.NewLine, "If you have already entered an Unlock Code in the LicenseManager,", Environment.NewLine, " did you link license objects into your application via the Microsoft license compiler?", Environment.NewLine, " (Make sure the needed components and correct VERSION are listed in the LICENSES.LICX file,", Environment.NewLine, " and that the LICENSES.LICX file is part of your EXECUTABLE's project, not in a DLL.)", Environment.NewLine }; string text9 = string.Concat(textArray1); text9 = text9 + text1; if (SystemInformation.UserInteractive) { MessageBox.Show(text9, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text9); } if (allowExceptions) { throw new LicenseException(type, instance, text9); } return null; }
/// <include file='doc\LicFileLicenseProvider.uex' path='docs/doc[@for="LicFileLicenseProvider.GetLicense"]/*' /> /// <devdoc> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </devdoc> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { ProcCountLicense lic = null; Debug.Assert(context != null, "No context provided!"); //if no context is provided, do nothing if (context != null) { //if this control is in runtime mode if (context.UsageMode == LicenseUsageMode.Runtime) { //retreive the stored license key string key = context.GetSavedLicenseKey(type, null); //check if the stored license key is null // and call IsKeyValid to make sure its valid if (key != null && IsKeyValid(key, type)) { //if the key is valid create a new license lic = new ProcCountLicense(this, key); } } //if we're in design mode or //a suitable license key wasn't found in //the runtime context. //attempt to look for a .LIC file if (lic == null) { //build up the path where the .LIC file //should be string modulePath = null; // try and locate the file for the assembly if (context != null) { ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolver != null) modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName()); } if (modulePath == null) modulePath = type.Module.FullyQualifiedName; //get the path from the file location string moduleDir = Path.GetDirectoryName(modulePath); //build the path of the .LIC file string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine("Path of license file: " + licenseFile); //if the .LIC file exists, dig into it if (File.Exists(licenseFile)) { //crack the file and get the first line Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); Debug.WriteLine("Contents of license file: " + s); //check if the key is valid if (IsKeyValid(s, type)) { //valid key so create a new License lic = new ProcCountLicense(this, s); } } //if we managed to create a license, stuff it into the context if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return lic; }
/// <summary> /// Extract the license for the given type from the given licenseKey /// </summary> /// <param name="context">The current licensing context</param> /// <param name="type">The type to be licensed</param> /// <param name="licenseKey">The encrypted hexadecimal license key</param> /// <returns>A license for the given type or NULL if the licenseKey was invalid</returns> protected virtual EncryptedLicense LoadLicense(LicenseContext context, Type type, string licenseKey) { // check that validation parameters have been set by the client // if (_designSignature == null || _runtimeSignature == null) throw new InvalidOperationException("EncryptedLicenseProvider.SetParameters must be called prior to using the EncryptedLicenseProvider"); if (licenseKey == null) return null; try { byte[] encData = FromHex(licenseKey); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Key = _desKey; des.IV = _desIV; byte[] data = des.CreateDecryptor().TransformFinalBlock(encData, 0, encData.Length); // extract the password data and encrypted product data // byte[] passwordData = new byte[ArraySize(_keyStrength)]; byte[] encPayload = new byte[ArraySize(data.Length - _keyStrength)]; // for key strengths greater than 8 the order of payload and key is swapped // if (_keyStrength < 8) { Array.Copy(data, 0, passwordData, 0, _keyStrength); Array.Copy(data, _keyStrength, encPayload, 0, encPayload.Length); } else { Array.Copy(data, 0, encPayload, 0, encPayload.Length); Array.Copy(data, encPayload.Length, passwordData, 0, _keyStrength); } // the key used to encrypt payload is just the first 7 bytes of the password data // byte[] encryptionKey = new byte[ArraySize(8)]; Array.Copy(passwordData, 0, encryptionKey, 0, 7); // validate that the password matches what the client is expecting // CspParameters cspParams = new CspParameters(); // if we are running in a server or ASP then ensure that we use the machine CSP // store to avoid problems. // if (!Environment.UserInteractive || UseMachineKeyStore) { cspParams.Flags = CspProviderFlags.UseMachineKeyStore; } RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspParams); rsa.ImportParameters(_rsaParameters); byte[] paddedPasswordData = PadPassword(passwordData); if (context.UsageMode == LicenseUsageMode.Designtime) { // if design time license requested then the license MUST be a design license // if (!rsa.VerifyData(paddedPasswordData, new SHA1CryptoServiceProvider(), _designSignature)) return null; } else { // if runtime license requested then first check if the license is a runtime license // also allow design licenses to work at runtime // if (!rsa.VerifyData(paddedPasswordData, new SHA1CryptoServiceProvider(), _runtimeSignature)) { if (!rsa.VerifyData(paddedPasswordData, new SHA1CryptoServiceProvider(), _designSignature)) return null; } } // decrypt the payload using the encryption key // des.IV = encryptionKey; byte[] payload = des.CreateDecryptor().TransformFinalBlock(encPayload, 0, encPayload.Length); int checksumLength = (_checksumProductInfo) ? 2 : 0; byte[] productData = new byte[ArraySize(payload.Length - 2 - checksumLength)]; Array.Copy(payload, 2, productData, 0, productData.Length); UInt16 serialNo = BitConverter.ToUInt16(payload, 0); string product = System.Text.ASCIIEncoding.UTF8.GetString(productData); // validate the product data checksum // if (_checksumProductInfo) { UInt16 requiredChecksum = BitConverter.ToUInt16(payload, payload.Length - checksumLength); UInt16 actualChecksum = Checksum(productData); if (requiredChecksum != actualChecksum) return null; } // if in design time then create a runtime license and save it // if (context.UsageMode == LicenseUsageMode.Designtime && type != null) { // create the runtime password by encrypting the design password // byte[] encPassword = des.CreateEncryptor().TransformFinalBlock(paddedPasswordData, 0, paddedPasswordData.Length); byte[] runtimePasswordData = new byte[ArraySize(_keyStrength)]; Array.Copy(encPassword, 0, runtimePasswordData, 0, _keyStrength); string runtimeLicenseKey = GenerateKey(_keyStrength, runtimePasswordData, productData,_checksumProductInfo, serialNo); // save the runtime key into the context // context.SetSavedLicenseKey(type, runtimeLicenseKey); } return new EncryptedLicense(licenseKey, serialNo, product); } catch { return null; } }
public override License GetLicense(LicenseContext context,Type type,object instance,bool allowExceptions) { DevCoLicense lic = null; Debug.Assert(context!=null, "No context provided!"); #if !TRIAL //if no context is provided, do nothing if (context != null) { //if this control is in runtime mode if (context.UsageMode == LicenseUsageMode.Runtime) { //retreive the stored license key string key = context.GetSavedLicenseKey(type, null); //check if the stored license key is null // and call IsKeyValid to make sure its valid if (key != null && IsKeyValid2(key, type)) { //if the key is valid create a new license lic = new DevCoLicense(key); } else { try { System.Reflection.Assembly[] assemblies=System.AppDomain.CurrentDomain.GetAssemblies(); foreach(System.Reflection.Assembly a in assemblies) { string codeBase = a.CodeBase; codeBase = codeBase.Substring(codeBase.LastIndexOf("/") + 1)+".licenses"; System.IO.Stream stream=this.GetManifestResourceStream(a,codeBase); if(stream==null) codeBase=codeBase.Replace(".DLL.",".dll."); stream=this.GetManifestResourceStream(a,codeBase); if(stream!=null) { key=DeserializeLicenseKey(stream); if (key != null && key!="") //IsKeyValid2(key, type)) { lic = new DevCoLicense(key); break; } } } } catch { lic=new DevCoLicense(""); } } } else { string sKey=""; Microsoft.Win32.RegistryKey regkey=Microsoft.Win32.Registry.LocalMachine; regkey=regkey.OpenSubKey("Software\\DevComponents\\Licenses",false); if(regkey!=null) { sKey=regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2").ToString(); } //check if the key is valid if (IsKeyValid(sKey, type)) { //valid key so create a new License lic = new DevCoLicense(Key(type)); } //if we managed to create a license, stuff it into the context if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } #else if (context != null) { lic=new DevCoLicense(""); //if this control is in runtime mode if (context.UsageMode == LicenseUsageMode.Runtime) { RemindForm frm=new RemindForm(); frm.ShowDialog(); } else { context.SetSavedLicenseKey(type, lic.LicenseKey); } } #endif if(lic==null && context!=null) { RemindForm frm=new RemindForm(); frm.ShowDialog(); lic=new DevCoLicense(""); } return lic; }