我想做一个JavaScript应用程序,不是开源的,因此我希望学习如何可以混淆我的JS代码?这可能吗?


当前回答

我的印象是,一些企业(例如:JackBe)将加密的JavaScript代码放在*.gif文件中,而不是JS文件中,作为一种额外的混淆措施。

其他回答

我可以推荐Patrick J. O'Neil的JavaScript Utility。它可以模糊/紧凑和压缩,它似乎很擅长这些。也就是说,我从未尝试将它集成到任何类型的构建脚本中。

至于混淆和缩小,我不太喜欢前者。它使调试不可能(错误在第一行…“等等,只有一行”),而且他们总是要花时间打开行李。但如果你需要…好。

我以前用过这个,它做得很好。它不是免费的,但你一定要看看。 JavaScript混淆器和编码器

你不能保护客户端代码:只需在谷歌Chrome上按F12,暂停javascript执行,你就会得到所有的字符串,即使是那些加密的。美化它和重命名变量,你会得到几乎原始的代码。

如果你正在编写服务器端javascript(即NodeJS),害怕有人入侵你的服务器,并想让黑客的工作更加困难,给你更多的时间来取回你的访问权限,那么使用javacript编译器:

你需要在高级编译中使用闭包编译器,因为它是唯一重命名所有变量的工具,即使这些变量在多个文件/模块中使用。但它有一个问题:它只有在你用它的编码风格写的时候才能工作。

有许多免费的JavaScript混淆工具;然而,我认为重要的是要注意,很难混淆JavaScript到不能进行逆向工程的地步。

为此,我在一定程度上使用了几个选项:

YUI Compressor. Yahoo!'s JavaScript compressor does a good job of condensing the code that will improve its load time. There is a small level of obfuscation that works relatively well. Essentially, Compressor will change function names, remove white space, and modify local variables. This is what I use most often. This is an open-source Java-based tool. JSMin is a tool written by Douglas Crockford that seeks to minify your JavaScript source. In Crockford's own words, "JSMin does not obfuscate, but it does uglify." It's primary goal is to minify the size of your source for faster loading in browsers. Free JavaScript Obfuscator. This is a web-based tool that attempts to obfuscate your code by actually encoding it. I think that the trade-offs of its form of encoding (or obfuscation) could come at the cost of filesize; however, that's a matter of personal preference.

你试过香蕉脚本吗?它生成高度压缩且完全不可读的代码。