SpringBoot使用classfinal-maven-plugin插件加密Jar包

jar包加密

1、在启动类的pom.xml中加入classfinal-maven-plugin插件

复制代码
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>net.roseboy</groupId>
                <artifactId>classfinal-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <password>#</password>              <!--启动密码,#为空-->
                    <excludes>org.spring</excludes>
                    <packages>${groupId}</packages>     <!--需要加密的包名,有多个使用逗号分隔-->
                    <cfgfiles>application.yml,spy.properties,ehcache.xml</cfgfiles>     <!--需要加密的配置文件,有多个使用逗号分隔-->
                    <libjars>SuperDog.jar</libjars>				<!--jar包lib目录下要加密的jar依赖,有多个使用逗号分隔-->
                    <code></code>                       <!--机器码,指定某个机器启动-->
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>classFinal</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>

2、在右侧的maven工具栏中使用install,xxx-encrypted.jar是加密后的jar包

3、加密后的jar包不能直接运行,要设置javaagent来启动,启动过程中会解密

复制代码
//无密码启动
java -javaagent:APF_AssetServer-encrypted.jar -jar APF_AssetServer-encrypted.jar

//有密码启动
java -javaagent:APF_AssetServer-encrypted.jar='-pwd=密码' -jar APF_AssetServer-encrypted.jar

//增加其他参数启动
java -javaagent:APF_AssetServer-encrypted.jar -jar -Xmx512m -Xms512m APF_AssetServer-encrypted.jar --spring.profiles.active=APF_AssetServer-encrypted

反编译效果

class文件只能看到方法名、参数和注解,方法内容被清空

配置文件变成空白

绑定机器启动

1、下载 classfinal-fatjar-1.2.1.jar

2、执行 java -jar classfinal-fatjar-1.2.1.jar -C

3、将生成的机器码,放到maven插件的code里

相关推荐
ruleslol1 天前
SpringBoot面试题03-BeanFactory
spring boot
刘一说1 天前
深入理解 Spring Boot 中的数据库迁移:Flyway 与 Liquibase 实战指南
数据库·spring boot·oracle
一叶飘零_sweeeet1 天前
SpringBoot 集成 RabbitMQ
spring boot·rabbitmq·java-rabbitmq
知兀1 天前
【Spring/SpringBoot】<dependencyManagement> + import 导入能继承父maven项目的所有依赖,类似parent
spring boot·spring·maven
手握风云-1 天前
JavaEE 进阶第五期:Maven 之道,项目的依赖艺术与构建哲学
java·java-ee·maven
郝开1 天前
Spring Boot 2.7.18(最终 2.x 系列版本):版本概览;兼容性与支持;升级建议;脚手架工程搭建
java·spring boot·后端
清水1 天前
Spring Boot企业级开发入门
java·spring boot·后端
Q_Q5110082851 天前
python+django/flask的校园活动中心场地预约系统
spring boot·python·django·flask·node.js·php
水冗水孚1 天前
类比前端知识来学习Java的Spring Boot实现MySql的全栈CRUD功能——搭配Svelte+Vite
spring boot·svelte
淘源码d1 天前
什么是医院随访系统?成熟在用的智慧随访系统源码
java·spring boot·后端·开源·源码·随访系统·随访系统框架