场景:
最近项目提出要对线上代码进行安全性处理,防止客户直接通过反编译工具将代码反编译出来
方案:
第一种方案使用的是代码混淆
第二种方案使用的是代码加密
方案比较
方案一:采用的proguard-maven-plugin插件
方案二:采用的classfinal-maven-plugin插件
在单模块中方案一还算简单,但是现在项目一般都是多模块,一个模块依赖多个模块,使用方案一非常麻烦,配置复杂,文档难懂,各模块之间的调用在是否要混淆时极容易出错。
在方案二中就简单很多,直接配置一个插件classfinal-maven-plugin就可以实现源码的安全性保护
综合比较果断使用方案二
官方文档:
ClassFinal: Java字节码加密工具
项目实例
只需要在启动类的pom.xml文件中加如下插件即可,需要注意的是改插件需要放到spring-boot-maven-plugin插件的后面,否则不起作用。
 <plugin>
			    <!-- https://gitee.com/roseboy/classfinal -->
			    <groupId>net.roseboy</groupId>
			    <artifactId>classfinal-maven-plugin</artifactId>
			    <version>1.2.1</version>
			    <configuration>
			        <password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
			        <packages>com.gisquest.cloud</packages>
			        <cfgfiles>application.properties</cfgfiles>
			        <excludes>org.spring</excludes>
			        <libjars>
				        platform-commons-1.0.0-SNAPSHOT.jar,
				        platform-commons-web-1.0.0-SNAPSHOT.jar,
				        platform-commons-web-db-1.0.0-SNAPSHOT.jar,
				        platform-multiappcenter-base-restful-1.0.0-SNAPSHOT.jar,
				        platform-multiappcenter-log-1.0.0-SNAPSHOT.jar,
				        platform-multiappcenter-var-restful-1.0.0-SNAPSHOT.jar,
				        platform-plugin-cache-1.0.0-SNAPSHOT.jar,
				        platform-plugin-authorization-1.0.0-SNAPSHOT.jar,
				        platform-plugin-configcenter-1.0.0-SNAPSHOT.jar,
				        platform-plugin-sleuth2x-zipkin-1.0.0-SNAPSHOT.jar,
				        platform-outerclient-1.0.0-SNAPSHOT.jar
			        </libjars>
			    </configuration>
			    <executions>
			        <execution>
			            <phase>package</phase>
			            <goals>
			                <goal>classFinal</goal>
			            </goals>
			        </execution>
			    </executions>
			</plugin> 
配置参数见官方文档,就几句中文
在改模块中使用maven-install时会再target目录下生成一个

因此在实际部署的时候将platform-multiappcenter-base-app-1.0.0-SNAPSHOT-encrypted.jar包放到线上运行即可
该加密的包解压后如下效果,业务逻辑不显示

该模块lib下依赖的 platform-commons-1.0.0-SNAPSHOT.jar解压后效果如下,同样是业务逻辑不显示,从而保证了代码的安全性



![[激光原理与应用-28]:《激光原理与技术》-14- 激光产生技术 - 激光的主要参数与指标](https://img-blog.csdnimg.cn/img_convert/9b0726ec89450c1fc978ba2757c1ef43.jpeg)
















