开发者

(C#/C++ CLI) Is it possible to protect my C++ CLI assemblies from being used in other .NET projects?

I have created a C++ CLI wrapper for native C++ code, which in turn I r开发者_运维技巧eference in my C# application. Is it possible to somehow protect this assembly so that it may only be used in my application without the possibility of someone else using it?

I'm a Microsoft technology developer, I'm all about selfishness :)


I have used this technique with success.

Basically, it's about protecting your assembly from being loaded by placing a link-time security demand and using the assembly strong name's public key as evidence. Only assemblies signed with your private key will be able to load it.


Yes, but this will be a losing battle against a determined attacker.

For example, you could provide an encrypted version that only accepts a particular key, as some people have suggested. But then you'll need to decrypt it on your clients, who may not have encrypted memory stores, so a determined attacker could simply read the appropriate block of memory and deserialize the result to get your original assembly.


Not perfectly. LinkDemand is only enforced in a partial trust environment. Code running with full trust can also use reflection to access private types, and generally bypass any protection you care to discuss.

Maybe you want your C++/CLI code to call Assembly::GetEntryAssembly and check it against a whitelist of approved apps for which the library is intended.

Of course, you want to minimize the amount of managed code (and attributes) involved in the checks since managed code is really easy to decompile.

Actually, mixing the occasional check into the core logic of the C++ code is the only hope you have that it won't be bypassed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜