如何将 C# 转换为 DLL 以隐藏源代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/515884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:25:48  来源:igfitidea点击:

How to convert C# to DLL to hide the source code?

c#visual-studiodllsource-code-protection

提问by Ali

How can I convert my C# code to DLL file in a way that the user of DLL can't view my source code?

如何以 DLL 的用户无法查看我的源代码的方式将我的 C# 代码转换为 DLL 文件?

When I make DLL in the way I always do by making a class library project, importing my classes and compiling it, the source code can still be viewed.

当我像往常一样通过创建类库项目、导入我的类并编译它来创建 DLL 时,仍然可以查看源代码。

采纳答案by JaredPar

I believe you are looking for an obfuscator. This is a tool that will take a compiled DLL and rewrite the code with the intent of it not being meaningfully decompiled by another user. Visual Studio comes with a free Dotfuscator

我相信你正在寻找一个混淆器。这是一个工具,它将获取已编译的 DLL 并重写代码,目的是不会被其他用户有意义地反编译。Visual Studio 附带免费的Dotfuscator

Note, this will not actually prevent people from looking at your code. They will instead be looking at a very weird translation of your code. There is no way to prevent people from looking at decompiled versions of your code in C# or any other .Net language for that matter.

请注意,这实际上不会阻止人们查看您的代码。相反,他们将查看您的代码的非常奇怪的翻译。没有办法阻止人们在 C# 或任何其他 .Net 语言中查看您的代码的反编译版本。

This is not something that is unique to C#. It is fact a flaw of every language in existence. It's perfectly possible to decompile C code. The difference though is it's much easier to maintain a lot of the original code structure when decompiling managed languages (.Net and Java for instance) because the metadata maintains the original structure.

这不是 C# 独有的东西。它实际上是存在的每种语言的缺陷。反编译 C 代码是完全可能的。但不同之处在于,在反编译托管语言(例如 .Net 和 Java)时,维护许多原始代码结构要容易得多,因为元数据维护了原始结构。

回答by Anton Gogolev

Consider using an obfuscator.

考虑使用混淆器

回答by Spence

obfuscation is what you want to search for.

混淆是您要搜索的内容。

There is a free one (that is limited) in visual studio called Dotfuscator.

Visual Studio 中有一个免费的(有限的)叫做 Dotfuscator。

Uses fancy methods to rename your code and alter flowpaths to obscure it.

使用奇特的方法重命名您的代码并更改流程以掩盖它。

回答by GvS

If you mean, the end-user can view your source code by decompiling it, you can protect yourself using an obfuscator.

如果您的意思是,最终用户可以通过反编译来查看您的源代码,那么您可以使用混淆器来保护自己。

There is standard obfuscator build in into Visual Studio. In the menu choose Tools / Dotfuscator community edition.

Visual Studio 中内置了标准的混淆器。在菜单中选择工具/Dotfuscator 社区版。

回答by Mohammed Nasman

If you are developing desktop applications converting your code to Dll will not hide the it( there are many tools to decompile the dll or exe files).

如果您正在开发桌面应用程序,将您的代码转换为 Dll 不会隐藏它(有许多工具可以反编译 dll 或 exe 文件)。

but if you are using Asp.Net, then you can compile your site to Dll, and the code will not be visible in the aspx pages, it will be compiled to Dll, you can do that by right click on your project on solution explorer, then choose Publish website

但是如果您使用的是 Asp.Net,那么您可以将您的站点编译为 Dll,并且代码在 aspx 页面中将不可见,它将被编译为 Dll,您可以通过在解决方案资源管理器上右键单击您的项目来实现,然后选择发布网站

But in all cases .Net Exe files and DLL will be easy to decompile and extract the source code again, unless you use tool to obfuscator your code.

但在所有情况下,.Net Exe 文件和 DLL 将很容易反编译并再次提取源代码,除非您使用工具来混淆代码。

回答by Coderer

I think my replyto a similar question about JavaScript obfuscation applies here as well: in short, why bother? Your question has already been answered here ("use an obfuscator"), but I thought it wouldn't hurt to find out what your motivations are. Generally, code that you give to people is "in the hands of the enemy" -- if somebody wants to use it/figure out how it works badly enough, they will.

我认为对一个关于 JavaScript 混淆的类似问题的回答也适用于这里:简而言之,为什么要麻烦?您的问题已在此处得到解答(“使用混淆器”),但我认为找出您的动机不会有什么坏处。通常,您提供给人们的代码“掌握在敌人手中”——如果有人想使用它/弄清楚它的工作原理是否足够糟糕,他们就会这样做。