views:

193

answers:

5

Can someone tell me what the best approach to protecting my component DLLs in .Net?

I've written a few DLL components which will be publicly available. They will be licensed accordingly but I want to programmatically make sure that no one is using the components within their solutions illegally.

Any ideas?

+3  A: 

The best thing you can do is to obfuscate your code. This won't be 100% safe and can be reverse engineered.

dotfuscator

is a nice one.

rahul
The code is already obfuscated and a license agreement is in place. The issue I want to protect against is other developers using the component library to suppliment their solutions in violation to the license agreement. I realise that it is their responsibility and that I would have to chase them but I wanted to know if there were any more steps I could take to make it more difficult to do?
Brian Scott
+1  A: 

Like phoenix said there is really no way to completely protect your code as they can still be decompiled via a tool like reflector.

One such tool would be to use Dotfuscator.

Mark
+3  A: 

Attempting to prevent people doing things at a technology level will only lead to the dedicated working around your efforts to stop them by means of reverse engineering (to which obfuscated code will never stop them, it will only slow them down), clean room design and so forth. Your best bet is to reinforce to those who are receiving a license to use your libraries the terms of use, and to uphold your legal rights to enforce the terms of use.

squeeks
I was gonna reply with a satirical answer: "[Obligatory cliched Stackoverflow answer saying how any form of copy protection or DRM is pointless]" but you beat me to it.
mackenir
+2  A: 

Short of "not distributing them" there is no 100% sure way to prevent unauthorized access.

You could look into hardware or software licensing devices. Sprinkle license checks throughout your code and if the device is not present simply abort everything.

Another idea and is to declare all your types in the assembly as internal then setup your main application EXE as a friend assembly with the InternalsVisibleTo assembly attribute. This is typically used for unit-testing internal members and I have no idea how secure it would be in practice. This would not prevent people from disassembly your assembly so you may still want to obfuscate and this doesn't work at all if you are selling the library and intend only for licenses customers to use it (because you would have to provide custom builds to every customer).

Brian Ensink
Thanks, i'll look into this a bit more. Cheers.
Brian Scott
+1  A: 

Since your code is already obfuscated, you can enforce the inbuilt classes to be instantiated with a license key before any of the methods are called. If you find that the key is not valid/present you can either display a message box or return an error/exception. There are many examples of where this is done (checkout Xceed.com for one) but as the previous posts suggest, its simply for discouraging the end users from trying to use your assembly illegally. Not completely prevent it. Given sufficient time and incentive, any thing can be broken.

ivymike
Do you have any examples of this being implemented? I can't see anything on codeproject etc. If I could at least check to make sure a license key was legitimate etc then this would be reassuring.
Brian Scott
I don't have any, but it should be fairly easy to implement. a) Implement a custom license verifying algo as a class.b) Make sure all your classes derive from it. For the amount of effort it takes to implement, it could be pretty harassing for those try to break it :).
ivymike
Ok, thanks. I'll look into this as well. I think this is essentially what I will require to ensure that access to using the dlls are guarded by me provided license keys etc.
Brian Scott