Spring Boot JAR 安全加密运行工具, 同时支持的原生JAR.
基于对JAR包内资源的加密以及拓展ClassLoader来构建的一套程序加密启动, 动态解密运行的方案, 避免源码泄露以及反编译.
mac更新brew,并安装go
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
更新
brew update
安装go
brew install go
检查go版本
go version
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.core-lib</groupId>
<artifactId>xjar-maven-plugin</artifactId>
<version>4.0.2</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<!--yoou can change install-->
<phase>package</phase>
<configuration>
<password>xxxx</password>
<!-- need enc resources -->
<includes>
<include>com/et/**</include>
<include>mapper/*Mapper.xml</include>
<include>config/**</include>
</includes>
<!-- no need enc resources -->
<excludes>
<exclude>static/**</exclude>
<exclude>META-INF/**</exclude>
</excludes>
<!--target jar dir -->
<targetDir>${project.build.directory}\xJarDir\</targetDir>
<!-- target jar name -->
<targetJar>zsplat.jar</targetJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
对于Spring Boot 项目或模块, 该插件要后于 spring-boot-maven-plugin 插件执行, 有两种方式:
也可以通过Maven命令执行
mvn xjar:build -Dxjar.password=io.xjar
mvn xjar:build -Dxjar.password=io.xjar -Dxjar.targetDir=/directory/to/save/target.xjar
但通常情况下是让XJar插件绑定到指定的phase中自动执行, 这样就能在项目构建的时候自动构建出加密的包.
mvn clean package -Dxjar.password=io.xjar
mvn clean install -Dxjar.password=io.xjar -Dxjar.targetDir=/directory/to/save/target.xjar
强烈建议不要在 pom.xml 的 xjar-maven-plugin 配置中写上密码,这样会导致打包出来的 xjar 包中的 pom.xml 文件保留着密码,极其容易暴露密码!强烈推荐通过 mvn 命令来指定加密密钥!
<project>
<!-- 设置 jitpack.io 仓库 -->
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<!-- 添加 XJar 依赖 -->
<dependencies>
<dependency>
<groupId>com.github.core-lib</groupId>
<artifactId>xjar</artifactId>
<version>4.0.2</version>
<!-- <scope>test</scope> -->
</dependency>
</dependencies>
</project>
package com.et.xjar;
import io.xjar.XCryptos;
public class JarEncryptio {
public static void main(String[] args) throws Exception {
// Spring-Boot Jar包加密
XCryptos.encryption()
.from("/Users/liuhaihua/IdeaProjects/springboot-demo/xjar/target/xjar-1.0-SNAPSHOT.jar")
.use("passwad")
.exclude("/static/**/*")
.exclude("/templates/**/*")
.exclude("/META-INF/resources/**/*")
.to("/Users/liuhaihua/IdeaProjects/springboot-demo/xjar/target/xJarDir/xjar-encryption.jar");
System.out.println("success");
}
}
mvn clean package
2.运行Java代码执行main方法加密
go build xjar.go
./xjar java --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED -jar xjar-encryption.jar