• 线上项目源码安全性处理方案


    场景:

    最近项目提出要对线上代码进行安全性处理,防止客户直接通过反编译工具将代码反编译出来

    方案:

    第一种方案使用的是代码混淆

    第二种方案使用的是代码加密

    方案比较

    方案一:采用的proguard-maven-plugin插件

    方案二:采用的classfinal-maven-plugin插件

    在单模块中方案一还算简单,但是现在项目一般都是多模块,一个模块依赖多个模块,使用方案一非常麻烦,配置复杂,文档难懂,各模块之间的调用在是否要混淆时极容易出错。

    在方案二中就简单很多,直接配置一个插件classfinal-maven-plugin就可以实现源码的安全性保护

    综合比较果断使用方案二

    官方文档:

    ClassFinal: Java字节码加密工具

    项目实例

     只需要在启动类的pom.xml文件中加如下插件即可,需要注意的是改插件需要放到spring-boot-maven-plugin插件的后面,否则不起作用。

    1. <plugin>
    2. <!-- https://gitee.com/roseboy/classfinal -->
    3. <groupId>net.roseboy</groupId>
    4. <artifactId>classfinal-maven-plugin</artifactId>
    5. <version>1.2.1</version>
    6. <configuration>
    7. <password>#</password><!--加密打包之后pom.xml会被删除,不用担心在jar包里找到此密码-->
    8. <packages>com.gisquest.cloud</packages>
    9. <cfgfiles>application.properties</cfgfiles>
    10. <excludes>org.spring</excludes>
    11. <libjars>
    12. platform-commons-1.0.0-SNAPSHOT.jar,
    13. platform-commons-web-1.0.0-SNAPSHOT.jar,
    14. platform-commons-web-db-1.0.0-SNAPSHOT.jar,
    15. platform-multiappcenter-base-restful-1.0.0-SNAPSHOT.jar,
    16. platform-multiappcenter-log-1.0.0-SNAPSHOT.jar,
    17. platform-multiappcenter-var-restful-1.0.0-SNAPSHOT.jar,
    18. platform-plugin-cache-1.0.0-SNAPSHOT.jar,
    19. platform-plugin-authorization-1.0.0-SNAPSHOT.jar,
    20. platform-plugin-configcenter-1.0.0-SNAPSHOT.jar,
    21. platform-plugin-sleuth2x-zipkin-1.0.0-SNAPSHOT.jar,
    22. platform-outerclient-1.0.0-SNAPSHOT.jar
    23. </libjars>
    24. </configuration>
    25. <executions>
    26. <execution>
    27. <phase>package</phase>
    28. <goals>
    29. <goal>classFinal</goal>
    30. </goals>
    31. </execution>
    32. </executions>
    33. </plugin>

    配置参数见官方文档,就几句中文 

    在改模块中使用maven-install时会再target目录下生成一个

     因此在实际部署的时候将platform-multiappcenter-base-app-1.0.0-SNAPSHOT-encrypted.jar包放到线上运行即可

     该加密的包解压后如下效果,业务逻辑不显示

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

  • 相关阅读:
    Swagger系列:SpringBoot3.x中使用Knife4j
    阿里云服务器配置选择指南(2023新版教程)
    04 Pytorch tensor
    Execution failed for task ‘:keyboard_utils:compileDebugKotlin‘.
    68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
    【操作系统】基础知识概述
    volatile底层原理的再次理解
    并查集的原理+例题
    Java 21 新功能展示(含示例)
    JavaScript排他思想小例子之按钮的点击效果
  • 原文地址:https://blog.csdn.net/qq_38423256/article/details/128152458