使用allatori对Spring boot项目的class文件进行混淆操作
- 工作小总结
- 时间:2023-08-10 11:06
- 2625人已阅读
简介
场景:环境:jdk版本:1.8springboot版本:2.7.11需要依赖的jar文件:在pom的文件中添加plugin。如下:org.apache.maven.plugins mav
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
场景:
环境:
jdk版本:1.8
spring boot版本:2.7.11
需要依赖的jar文件:

在pom的文件中添加plugin。如下:
<!-- allatori 文件copy -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-allatori</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>./target/</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>allatori.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- exec 执行allatori jar 混淆处理 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run-allatori</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>./lib/allatori.jar</argument>
<argument>${basedir}/target/allatori.xml</argument>
</arguments>
</configuration>
</plugin>allatori的配置文件信息:
<config> <!-- 输入输出混淆的jar文件 --> <input> <jar in="kaigejava.jar" out="kaigejava-obfuscated.jar"/> </input> <!-- 忽略混淆的classes文件 --> <ignore-classes> <class template="class *Application*" /> <class template="class org.springframework*"/> <class template="class org.apache.ibatis*"/> <class template="class com.hdtd.business.typicalday.util.DateRangMatchUtil"/> </ignore-classes> <!-- 保持不混淆的策略文件 --> <keep-names> <!-- protected/public保护的类名及方法名称都保留不混淆 --> <class access="protected+"> <field access="protected+" /> <method access="protected+" /> </class> </keep-names> <!-- 混淆过程的日志文件 --> <property name="log-file" value="log.xml"/> </config>
添加完成之后,执行maven install下看看效果。
生成的kaigejava.jar是未加密的
kaigejava-obfuscated.jar这个是加密的
效果:
