Mac jar包混淆加密

Mac jar包混淆加密

废话不多说,直接上案例

Allatori 混淆器

Allatori具有以下几种保护方式:命名混淆,流混淆,调试信息混淆,字符串混淆,以及水印技术。对于教育和非商业项目来说这个混淆器是免费的。支持war和jar文件格式,并且允许对需要混淆代码的应用程序添加有效日期。 有项目需要对代码进行保护,比较初级的方案就是对代码进行混淆,打包之后的文件进行反编译后,就可以看到效果。

官方文档 - https://allatori.com/doc.html

对自身项目有一定的侵入性,需要引入jar包,xml文件,修改pom文件
jar通过官网下载
在这里插入图片描述
解压后得到lib的jar
在这里插入图片描述

1、jar包copy进项目
2、修改pom文件
<dependencies>
 <dependency>
            <groupId>com.allatori</groupId>     <!-- 自定义即可 -->
            <artifactId>allatori</artifactId>    <!-- jar名称 -->
            <version>1.0</version>          <!-- 如果jar包未指定自定义即可-->
            <type>jar</type>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/allatori.jar</systemPath>    <!-- 使用jar所在的绝对路径 -->
        </dependency>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
            <type>maven-plugin</type>
        </dependency>

    </dependencies>


<build>
        <plugins>
            <!--  springboot 项目编译 此插件不能少,否则会报异常主清单不存在          -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- resouces拷贝文件插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <!-- 插件执行的时候申明所有的phase-->
                <executions>
                    <execution>
                        <id>copy-allatori-config</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <!-- 拷贝文件的目录,我们最终打包存放的位置是target目录 -->
                            <outputDirectory>${basedir}/target</outputDirectory>
                            <resources>
                                <resource>
                                    <!-- 这个目录放recsource,是因为resource打包时本身会被copy到target中 -->
                                    <directory>src/main/resources</directory>
                                    <includes>
                                        <!-- Allatori配置文件的文件名 -->
                                        <include>allatori.xml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- 执行java程序,这里执行的是混淆的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>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executable>java</executable>
                    <arguments>
                        <argument>-Xms128m</argument>
                        <argument>-Xmx512m</argument>
                        <argument>-jar</argument>
                        <!-- 指定应用的Allatori的jar包的位置 -->
                        <argument>lib/allatori.jar</argument>
                        <!-- allatori配置文件要放到target下,不设置 混淆jar包不生效 -->
                        <argument>${basedir}/target/allatori.xml</argument>
                    </arguments>
                </configuration>
            </plugin>

        </plugins>
    </build>

3、添加xml文件

在resources下面添加allatori.xml

<!--allatori配置文件-->
<config>
    <!-- 输入和输出jar配置,out指向的是加密后的jar -->
    <input>
        <jar in="项目名.jar" out="重新命名.jar"/>
    </input>
    <!-- 加水印 -->
    <watermark key="secure-key-to-extract-watermark" value="developer: xxx"/>
    <!-- 需要保留原来类名的配置 -->
<!--   <classpath>-->
<!--&lt;!&ndash;            此处jar包位置为target的数据 不需要不要加  &ndash;&gt;-->
<!--        <jar name="ROOT/WEB-INF/lib/*.jar"/>-->
<!--    </classpath>-->
    <keep-names>
        <class access="protected+">
            <field access="protected+"/>
            <method access="protected+"/>
        </class>
  
    </keep-names>
        <!--此为log日志 可不用-->
    <property name="log-file" value="log.xml"/>
    <ignore-classes>
        <!-- 配置启动类不被混淆  保证springBoot可以正常启动 -->
        <class template="class *Application*" />

        <class template="class *springframework*"/>
        <class template="class *shardingjdbc*"/>
        <class template="class *jni*"/>
        <class template="class *alibaba*"/>
        <class template="class *persistence*"/>
        <class template="class *apache*"/>
        <class template="class *mybatis*"/>
        <!-- 排除包下的类,可单个到具体,注意此处一定要排除掉springboot项目的启动类 -->
        <class template="class com.apache.*"/>
        <class template="class org.apache.http.entity.StringEntity"/>
        <class template="class org.apache.cxf.*"/>
        <class template="class 启动类"/>
    </ignore-classes>
</config>

4、maven clean install 即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值