版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
方案一:xjar - Spring Boot JAR 安全加密运行工具
GitHub: https://github.com/core-lib/xjar
基于对JAR包内资源的加密以及拓展ClassLoader来构建的一套程序加密启动,动态解密运行的方案,避免源码泄露或反编译。
这里只是最最简单场景下的使用步骤,进阶用法请参考官网。
1. 添加依赖
在pom中project节点下添加jitpack仓库
<!-- 设置 jitpack.io 仓库 -->
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>
</repositories>
添加xjar依赖
<!-- 添加 XJar 依赖 -->
<dependency>
<groupId>com.github.core-lib</groupId>
<artifactId>xjar</artifactId>
<version>v1.1.4</version>
</dependency>
2. Springboot Jar包加密
@Test
public void test() throws Exception {
String password = "io.xjar";
XBoot.encrypt("D:/test/test.jar", "D:/test/encryptedTest.jar", password,
new XJarRegexEntryFilter("BOOT-INF/classes/com/.+?"));//只加密classes/com下的文件
System.out.println("done");
}
// 危险加密模式,即不需要输入密码即可启动的加密方式,这种方式META-INF/MANIFEST.MF中会保留密钥,请谨慎使用!
String password = "io.xjar";
XKey xKey = XKit.key(password);
XBoot.encrypt("/path/to/read/plaintext.jar", "/path/to/save/encrypted.jar", xKey, XConstants.MODE_DANGER);
3. 运行jar
java -jar encryptedTest.jar --xjar.password=io.xjar
方案二:ProGuard - 代码混淆
官网:https://www.guardsquare.com/en/products/proguard
参考:https://blog.csdn.net/u010142437/article/details/72819771
方案三:Allatori- 代码混淆
官网:http://www.allatori.com/
参考:https://github.com/Lovnx/confusion