如何保护我的程序集不被其他人使用?

发布于 2024-08-13 05:23:36 字数 101 浏览 8 评论 0原文

我怎样才能保护我的程序集,因为一旦我部署了设置, 程序集也将被部署,并且用户有可能从程序文件中获取程序集,并且可以添加对任何其他项目的引用或基于它创建新项目!任何解决方案或帮助将不胜感激。

how can I protect my assembly, because once I deploy the setup,
assembly will be deployed too, and there are chances that user will get the assembly from Program Files, and may add reference to any other project or create new project based on it ! any solution or help would be appreciated thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夜灵血窟げ 2024-08-20 05:23:36

您可以将程序集中的所有成员设置为内部成员,并且仅允许其他人通过 InternalsVisibleToAttribute。但如果有人足够坚持,就没有办法阻止他们使用它。

You can make all members inside the assembly internal, and only allow others to use it by the InternalsVisibleToAttribute. But if someone is persistent enough, there is no way to stop them from using it.

最偏执的依靠 2024-08-20 05:23:36

您可以混淆程序集的代码,这将使使用它的任务变得更加困难,但是有您无法采取任何措施来 100% 阻止用户挑选组件并使用。您可以做的不是在用户计算机上部署程序集,而是通过 Web 服务提供功能。

You could obfuscate the code of your assembly which will render the task of using it more difficult but there's not much you can do to 100% prevent a user from picking the assembly and using. What you could do is NOT to deploy the assembly on the user computer but provide the functionality through a web service.

最佳男配角 2024-08-20 05:23:36

你无法完全阻止这种情况。但是您可以以某种方式混淆程序集,使公开的类和方法没有任何合理的名称。

其中一种混淆器是开源的,称为 obfuscar。可以在此链接下找到继续项目。

You can't totally prevent that. But you could obfuscate your assembly in a way such that the classes and methods exposed don't have any reasonable names.

One such obfuscator is opensource and called obfuscar. A continued project can be found here under this link.

小…楫夜泊 2024-08-20 05:23:36

没有简单的方法。你只能让事情变得更加困难。如果您的算法是如此独特和宝贵[1],以至于您需要让第三方无法使用(或窥视)它们,那么您唯一的选择就是将逻辑放在远程位置(服务器后面)并让您的程序调用它。

[1] 根据我的卑微经验,事实并非如此。

There is no simple way. You can only make it more difficult. If your algorithms are so unique and precious[1] that you need to make them impossible for third parties to use (or peek in), your only choice is to have the logic in a remote place (behind a server) and have your program call it.

[1] Something that, in my humble experience, is never the case.

棒棒糖 2024-08-20 05:23:36

您可以使用 ILmerge 将程序集合并到可执行文件中,然后使用混淆来保护整个包(.NET 可执行文件可以被视为可以链接到的程序集)。

You could use ILmerge to merge the assembly into the executable, and then use obfuscation to protect the whole package (.NET executables can be treated as assemblies you can link to).

寂寞美少年 2024-08-20 05:23:36

虽然它显然不安全 - 您仍然必须将解密密钥存储在某处 - 它可以很好地加密磁盘上的 DLL,然后加载它们并在内存中解密。

如果您使用自定义处理程序挂钩 AppDomain.CurrentDomain.AssemblyResolve,您甚至可以透明地执行此操作 - 当您的程序集尝试加载特定 DLL 时,它会失败,您的处理程序会触发,并从加密的 DLL 加载程序集。

我还没有发现这种方法有任何问题。

另外,如果您只担心人们在自己的项目中使用您完成的 DLL,您可以在代码中添加一些堆栈检查,以及解析正在运行的程序集并对其执行哈希检查。不过,这两种对策都可以轻松地从 DLL 中编辑出来。

While it obviously isn't secure - you still have to store the decryption key somewhere - it works perfectly fine to encrypt your DLLs on disk, then load them and decrypt in memory.

If you hook AppDomain.CurrentDomain.AssemblyResolve with a custom handler, you can even do it transparently - when your assembly tries to load a specific DLL, it fails, your handler fires, and loads the assembly from the encrypted DLL.

I've yet to find any problems with this approach.

Also, if you're only worried about people using your finished DLLs in their own projects, you could add a few stack checks to your code, as well as resolving which assembly is running and performing a hash check on it. Both of these countermeasures can easily be edited out of your DLL, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文