How can I limit the loading and execution of my libraries based on a defined precondition? For example, if I distribute to a client an application that uses an external library, how can I ensure the external library is only used with the application and not used by the client for other purposes?
Is code access security the answer? If so, is there a good example of how to apply it in the situation described above?
Thanks!
UPDATE: I cannot use services to protect the logic开发者_运维技巧. I must supply the code in an assembly, and want to protect it from being used to build other products.
The best way to limit access is to move the logic from an assembly into a service layer. If you are truly concerned about protecting the logic in that assembly this is the best way.
Remember, any mechanism can be defeated with enough effort if the client has the assembly in their hands and is truly motivated to use it. That is why a service layer is a perfect solution as it gives your application access to the logic without allowing the client to obtain the implementation itself.
You should look into code obfuscation Nothing that you do will prevent someone dedicated enough from using the logic contained in your assembly however they see fit, however obfuscation will make it a more difficult and will hopefully deter most people.
See this question for more information
There's a build option to only allow friendly assemblies to use yours but that implies you can sign both your assembly and your client's as well. I doubt what you want to do is possible witout some sort of service layer or authentication/connection limitation to a server logic. Sorry.
Just a thought here and definitely this is not the safest or best way. Maybe just a small work around.
Instead of sending the assembly with the executable, how about moving the assembly to the Global Assembly Cache (GAC) and modifying the executable code to access the assembly present in the GAC? You can then change the name of the assembly to some garbage name (or whatever you think suitable) which the client will not be able to understand. So finding your assembly in that forest of assemblies would be almost impossible.
Hope this helps!
Regards,
Samar
精彩评论