使用allatori混淆spring cloud代码
上一篇使用progurad混淆spring cloud代码,实际看下来发现混淆代码效果不好,价值不大。于是改换为:allatori,在参考网上代码后,终于实验成功,过程如下:
在代码的根目录下新建文件夹lib,下载allatori,地址,下载完成后,将allatori拷贝到lib文件夹(目前已经到8.0版了)
然后在文件夹中建立配置文件,allatori.xml:
<config> <input> <!-- in表示输出的原始jar包,out表示输出的混淆后的jar包,后者名称可自定义,也可以是war --> <jar in="api-1.0-SNAPSHOT.jar" out="api-encrypted.jar"/> </input> <keep-names> <class access="protected+"> <field access="protected+"/> <method access="protected+"/> </class> <!-- 视图层的方法参数名称不做混淆,否则传参会对应不上,不怕麻烦的也可以加@RequestParam指定入参名称 --> <class template="class *Controller"> <method template="private+ *(**)" parameters="keep"/> </class> </keep-names> <property name="log-file" value="log.xml"/> <!-- 忽略的包或类,这些文件将不被混淆 --> <ignore-classes> <class template="class *springframework*" /> <class template="class *shardingjdbc*" /> <class template="class *jni*" /> <class template="class *alibaba*"/> <class template="class *persistence*"/> <!-- 排除业务类 --> <class template="class cn.*******.App"/> <class template="class cn.*******.entity.*" /> <class template="class cn.*******.mapper.*" /> <class template="class cn.*******.web.*" /> </ignore-classes> <!-- 到期时间(到期后无法启动jar) 格式:yyyy/mm/dd--> <!--<expiry date="2021/04/03" string="SERVICE EXPIRED!"/>--> <!-- 随机命名混淆字符,默认用当前时间,每次打包混淆的类名、变量名都不一样,如果做了配置那么两次打包内容就一样--> <!--<property name="random-seed" value="abcdef ghnljk svi"/>--> </config>
然后,在pom文件中引入2个插件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-and-filter-allatori-config</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target</outputDirectory> <resources> <resource> <directory>${basedir}/lib</directory> <includes> <include>allatori.xml</include> </includes> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- Allatori 插件 --> <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> <executable>java</executable> <arguments> <argument>-Xms128m</argument> <argument>-Xmx512m</argument> <argument>-jar</argument> <argument>${basedir}/lib/allatori.jar</argument> <argument>${basedir}/target/allatori.xml</argument> </arguments> </configuration> </plugin>
另外,最好携带上maven打包插件,这样打包时会携带上所需要的jar
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
然后打包,打包后再点击package,则会将打包后的jar加密成可执行的加密包。
参考:allatori代码混淆实现(springboot、springmvc)
分类:
Java相关技术
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构