.NET Framework gives a license for the application (below)

zhaozj2021-02-11  158

BY KENN SCRIBNER Translation: Zou Jianqiang Registry License provider As I mentioned earlier, most licensed verification work is done by your license provider's getLicense () method. Here some code is written for my own registry license provider (you can find in the source file example of registrylicenseprovider.cs): Public override License GetLicense (LicenseContext Context, Type Type, Object Instance, Bool AllowExceptions) { // We'll Test for the usage mode ... Run Time V. Design Time. // Note We Only Check if Run Time ... if (Context.usageMode == LicenseUsageMode.Runtime) {// The registry Key WE 'll check RegistryKey licenseKey = Registry.CurrentUser.OpenSubKey ( "Software // Acme // hostKeys"); if (! licenseKey = null) {// Passed the first test, which is the existence of the // Registry key itself. now obtain the stored value // associated with our app's GUID string strLic = (string) licenseKey.GetValue (type.GUID.ToString ());.! // reflected if (! strLic = null) {// Passed the second test Which is some value // exisss That's associated with our app's guid. if (String.comPare ("Installed", Strlic, False == 0) {// got it ... Valid license ... Return New RuntimeRegistryLicense (TYPE);} // if} // if} // if

// if we got this far, we failed the license test. we beginning // check to see if Exceptions area allowed, and if so, throw // a new license exception ... if (allowexceptions == true) {throw new LicenseException (Type, Instance, "Your license is invalid);} // if

// Exceptions Are Not Desired, So We'll Simply Return Null. Return Null;} // if else {return new design;} // else} The following section checks the code is more interested, we can check Currently running in what model is design or running: if (context.usagemode == licenseusagemode.Runtime) {... // run time mode} else {... // design time mode} // else In design, we will simply create and return an instance of the license object when we design: Return New DesigntormRylicense; however, if it is running, we can open our special registration key to find our application. GUID key value pair. Let's open the registry key as follows: registryKey licenseKey = registry.currentuser.opensubkey ("Software // Acme // HostKeys); We generate this key value by reflecting the application GUID. This GUID comes from the object we get (I still remember the GuidAttribute property of our license type): string strlic = (string) licenseKey.getValue (type.guid.tostring ()); getValue () method is not returned to this The value associated with the key is returning null, so we test the NULL value, check the value of our expectation returns to a legal license: if (strlic! = Null) {// Passed the second test, Which IS Some Value // EXISTS That's Associated with Our App's Guid. IF (String.com) == 0) {// got it ... Valid License ... return new runtimegegegegegegegeregistryLicense (TYPE) } // if} // if everything is normal, we will return a new instance of our runtime license object. Otherwise we will check if you are allowed, if you throw a new license exception: if (allowexceptions == true) {throw new licenseException (Type, Instance, "Your license is invalid");} // if Allowable, we return to NULL. This situation is the same, but the same is not required. The runtime license is displayed as follows: public class runtimeregistryLicense: license {private type type;

public RuntimeRegistryLicense (Type type) {if (type == null) throw new NullReferenceException ( "The licensed type reference may not be null."); this.type = type;} public override string LicenseKey {get {// Simply return the Application's Guid Return Type.Guid.toString ();}} public override void dispose ()}} I have to overload this licenseKey property (it is Abstract method) because of the base class license. When required, the GUID of the application will be returned. Anyway, I can re-get the registry value or check the regular failure and some illegal conditions. More other license programs I have a quite basis for the skills of demonstration here. But on the one hand, many users cannot open the registry without having a lot of help, and some people have considerable ability to crack this solution. Therefore, what you have to do is to make your license scheme more difficult to crack. The most obvious thing you have to do is replacing my simple "installed" string with a product validity period (and encrypt this value). Or you write a more complex license provider that makes it calls the Windows or Web services to apply for a license to perform an application. I have written very effective in these two ways. As I mentioned, the license object itself can make himself invalid, forcing the application to shut down, it is just a certificate of invalid. Permit the license of this application can determine the daily license status of this application from a Web service or a license to be checked. In any case, you have to make sure you have confused your product compilation! Conclusion If you have read here and study basic box plus licensing process, you may be strange: Why is I why do you write so much? Is it limited to this framework (.NET FRAMEWORK)? Do we have difficulties can't create a licensed manager? Why is there a non-framework for license? Just enable exceptions for a Boolean line getLicense () method? (I personally want to specify a attribute to licenseManger or a certificate of document rather than passing a Boolean value to getLicense () ... I haven't seen any other way to change the default frame behavior) I can only assume the framework The license architecture is more beneficial to your future development. After all, you have to follow the model specified in the framework, and change the framework may have a certain impact on you. Because you must use some of the components provided by some frameworks, reuse these resources can save (even less) your maintenance overhead. As far as the license itself, the only limit is your own imagination.

转载请注明原文地址:https://www.9cbs.com/read-5929.html

New Post(0)