对springboot项目进行代码混淆,可以防止别人通过反编译项目查看代码,即使反编译了查看的也是混淆后的看不懂的代码。
一定程度保证了项目源码安全性。
下面分享代码混淆步骤和反编译操作

Allatori-7.7 代码混淆操作步骤

使用方法

1、首先从官网下载:http://www.allatori.com/

​ 我的文件不是从官网下载的其他地方也可以找到资源
后面会附上资源包
代码混淆工具下载

2、下载完解压,解压之后的目录是这样的:
在这里插入图片描述
将jar包放入项目中(/lib目录里面的两个文件)
在这里插入图片描述

  1. 配置maven插件,如果是maven多模块,可以将jar包提取到父目录共用,xml文件各自配置各自的

<plugin> <!-- 这个也要加,,没加之前一直报错 -->
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
  </plugin>

            <!-- Allatori plugin start -->
            <plugin>
                <!-- resouces拷贝文件插件 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <!-- 执行这个插件的时候执行申明的所有phase -->
                <executions>
                    <execution>
                        <id>copy-and-filter-allatori-config</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <!-- 指明文件的输出路径 即混淆后的文件的输出路径 ${basedir}:是项目的根目录 即与src同级的目录 -->
                            <outputDirectory>${basedir}/target</outputDirectory>
                            <resources>
                                <resource>
                                    <!-- 项目的resources目录,一般用于存放配置文件 -->
                                    <directory>src/main/resources</directory>
                                    <includes>
                                        <!-- 代码混淆时所依据的配置文件 可以看出,我放在了resources目录下   这个文件将会被拷贝到 ${basedir}/target 目录下-->
                                        <include>allatori.xml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- 代码混淆打包插件 -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>run-allatori</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-Xms128m</argument>
                        <argument>-Xmx512m</argument>
                        <argument>-jar</argument>
                        <!-- 指定引用的allatori的jar包位置,这里把jar包放在了根目录下的lib目录里 -->
                        <argument>${basedir}/lib/allatori.jar</argument>
                        <!-- 指定代码混淆时的配置文件,因为是混淆指定的是jar包,jar包位置在target下,所以我们的allatori.xml也需要拷贝到该目录下(上面的拷贝文件插件已经帮我们做了这些事) -->
                        <argument>${basedir}/target/allatori.xml</argument>
                    </arguments>
                </configuration>
            </plugin>
            <!-- Allatori plugin end -->

配置allatori.xml文件,配置混淆规则 文件放在/src/resources/下面
在这里插入图片描述

<config>
    <input>
        <jar in="licensemanagement-1.0-SNAPSHOT.jar" out="aa-allatori.jar"/>
    </input>

    <ignore-classes>
        <class template="class *springframework*"/>
        <class template="class *jni*"/>
        <class template="class *alibaba*"/>
        <class template="class *persistence*"/>
        <class template="class *apache*"/>
        <class template="class *mybatis*"/>
        <class template="class *github*"/>

        <class template="class com.lpx.licensemanagement.anotation.*"/>
        <class template="class com.lpx.licensemanagement.aspect.*"/>
        <class template="class com.lpx.licensemanagement.async.*"/>
        <class template="class com.lpx.licensemanagement.config.*"/>
<!--        <class template="class com.lpx.licensemanagement.controller.*"/>-->
        <class template="class com.lpx.licensemanagement.entity.*"/>
        <class template="class com.lpx.licensemanagement.enums.*"/>
        <class template="class com.lpx.licensemanagement.exception.*"/>
        <class template="class com.lpx.licensemanagement.filter.*"/>
        <class template="class com.lpx.licensemanagement.interceptor.*"/>
        <class template="class com.lpx.licensemanagement.interfaces.*"/>
        <class template="class com.lpx.licensemanagement.mapper.*"/>
        <class template="class com.lpx.licensemanagement.pojo.*"/>
        <class template="class com.lpx.licensemanagement.service.*"/>
        <class template="class com.lpx.licensemanagement.utils.RedisOperator"/>
        <class template="class com.lpx.licensemanagement.LicenseManagementApplication"/>



    </ignore-classes>
    <keep-names>
        <class access="protected+">
            <field access="protected+"/>
            <method access="protected+"/>
        </class>
        <!-- 所有方法名称不变  parameters="keep" 表示方法的形参也不变 方法形参混淆后会导致参数映射获取失败 -->
        <!--<method template="*(**)" parameters="keep" />-->
        <!-- 控制层 方法名、方法、形参 不混淆 -->
        <class template="class com.lpx.licensemanagement.controller.*">
            <method template="protected+ *(**)" parameters="keep"/>
        </class>
        <!--        <class template="class com.lpx.test.service.*">-->
        <!--            <method template="protected+ *(**)" parameters="keep"/>-->
        <!--        </class>-->
    </keep-names>
    <property name="log-file" value="log.xml"/>
</config>

配置好后打包即可

mvn clean install -Dmaven.test.skip=true

在这里插入图片描述

当出现下图则说明混淆成功
在这里插入图片描述

此时target目录下会生成混淆后的jar包
在这里插入图片描述

反编译步骤

可以使用反编译工具查看混淆后的jar包代码是否成功混淆(我使用的是jd-gui)
反编译工具百度和CSDN很容易就能找到资源,你们自己下载一下。
资源链接
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐