java 将源代码隐藏在 .jar 文件中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14492422/
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-10-31 16:27:08  来源:igfitidea点击:

Hiding the source code in .jar files

javaencryptionencodingobfuscation

提问by AGEM

One can easily extract the .jarfile and see source code. I want to protect the source code from being seen. One possible answer is to password protect the file like we do it for zip files.

人们可以轻松地提取.jar文件并查看源代码。我想保护源代码不被人看到。一种可能的答案是使用密码保护文件,就像我们对 zip 文件所做的那样。

But, if the password is known, then the source code can be easily seen.

但是,如果知道密码,则很容易看到源代码。

Are there any ways of hiding the source code and still have it be able to run? Something similar to what a .exedoes in Windows. This should run in both windows as well as Linux environment.

有什么方法可以隐藏源代码并且仍然可以运行吗?类似于 a.exe在 Windows 中所做的事情。这应该在 Windows 和 Linux 环境中运行。

回答by gerrytan

Have a look at ProGuard, it's a popular obfuscator for java. As for packaging your java program as windows executable, this post might help you: How can I convert my Java program to an .exe file?

看看ProGuard,它是一个流行的 Java 混淆器。至于将您的 Java 程序打包为 Windows 可执行文件,这篇文章可能对您有所帮助:如何将我的 Java 程序转换为 .exe 文件?

回答by Peter Wooster

What you want to search for is "java obfuscation". There are lots of tools to help with this, but it is a losing battle if the people who want your code really want it. If this is a serious problem you should write in C++.

您要搜索的是“java 混淆”。有很多工具可以帮助解决这个问题,但是如果想要你的代码的人真的想要它,那将是一场失败的战斗。如果这是一个严重的问题,您应该用 C++ 编写。

回答by Stephen C

One can easily extract the .jar file and see the source code.

人们可以轻松地提取 .jar 文件并查看源代码。

Strictly speaking, that is not true. Unless you've actually included the source code files in the JAR, someone cannot see the original source code. But they can (typically) decompile the ".class" files in your JAR file to Java source code that is functionally equivalentto your original source code.

严格来说,这不是真的。除非您确实在 JAR 中包含了源代码文件,否则别人是看不到原始源代码的。但是它们(通常)可以将 JAR 文件中的“.class”文件反编译为 Java 源代码,该代码在功能上与您的原始源代码等效

As other answers have stated, you can make it harder for someone trying to reverse engineer your code; e.g. by using an obfuscator, or custom classloader that decrypts code that is stored in encrypted form in your JAR file. But nothing you can do is sufficient to prevent a determined hacker from defeating your measures. NOTHING.

正如其他答案所述,您可以让试图对您的代码进行逆向工程的人更难;例如,通过使用混淆器或自定义类加载器来解密以加密形式存储在 JAR 文件中的代码。但是,您无能为力,无法阻止坚定的黑客破坏您的措施。没有什么。

The only practical way to protect your code against reverse engineering is to not release it. Or use software licensing or other legal means to achieve your ends.

保护您的代码免受逆向工程影响的唯一实用方法是不发布它。或者使用软件许可或其他合法手段来达到您的目的。

回答by thkala

If you intend to simply discourage casual viewers then any of the many code obfuscation tools for Java would probably be of help. It will mess the bytecode enough to make your algorithms less obvious.

如果您打算简单地阻止随意的查看者,那么许多 Java 代码混淆工具中的任何一个都可能会有所帮助。它会弄乱字节码,使您的算法不那么明显。

If, on the other hand, you need "absolute" protection, any encryption/obfuscation tool would be useless - if your computer can run it then a determined and knowledgeable attacker would be able to eventuallyfigure out how your code works.

另一方面,如果您需要“绝对”保护,则任何加密/混淆工具都将毫无用处——如果您的计算机可以运行它,那么坚定且知识渊博的攻击者最终将能够弄清楚您的代码是如何工作的。

A couple of possible solutions:

几个可能的解决方案:

  • Use a client/server architecture to run the proprietary parts on computers that you own, so that you do not have to include the more interesting part of your code in your client application. Naturally this solution is not always feasible for a variety of reasons.

  • Hire a couple of lawyers that specialize in Intellectual Property issues and patentyour algorithms. In my opinion this is far batter an alternative than trying to force a technical solution on a non-technical problem...

  • 使用客户端/服务器架构在您拥有的计算机上运行专有部分,这样您就不必在客户端应用程序中包含代码中更有趣的部分。当然,由于各种原因,这种解决方案并不总是可行的。

  • 聘请几位专门处理知识产权问题并为您的算法申请专利的律师。在我看来,这远比试图强制解决非技术问题的技术解决方案要好得多......

回答by Dheeraj Sachan

Search for "java obfuscation". There are lots of tools to help with this, but if someone is really hell bent on retrieving source code you cannot stop him. To implement security related stuff you should write code in C++ then create dynamic library (.dll for windows and .so for linux ) and use java jni to use them.

搜索“java混淆”。有很多工具可以帮助解决这个问题,但如果有人真的一心想检索源代码,你就无法阻止他。要实现与安全相关的东西,您应该用 C++ 编写代码,然后创建动态库(Windows 为 .dll,Linux 为 .so)并使用 java jni 来使用它们。

on windows you can use mingw for compiling code.

在 Windows 上,您可以使用 mingw 来编译代码。

have a look at this https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

看看这个 https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html