当前位置: 首页 > news >正文

java 代码加密混淆之Allatori

全是干货,仅供参考,不喜勿喷,有问题欢迎交流!若能帮助您之万一,节省您工作中一点点时间,吾心甚慰。
关键字:java、springboot、idea、maven、allatori。
一、下载混淆组件
1、 下载最新版,官网https://allatori.com/
2、 本实例,使用包Allatori-9.5-Demo.zip解压后目录:
lib下混淆使用的jar组件,tutorial下是一些例子。
image
二、集成到idea maven环境
1、将lib文件夹拷贝到idea项目目录(或者公共目录)下,确保项目(模块)找到。
2、在项目(模块)根目录(src平级)添加allatori.xml文件,可在tutorial例子中找到一个allatori.xml添加到项目中。
3、配置allatori.xml文件,此文件对哪些类混淆,怎么混淆做配置;本文章一个样例allatori.xml文件(见代码实例)。
官网帮助文档:https://allatori.com/doc.html
关键配置说明:
Input 节点配置要混淆的jar文件,in为输入jar文件,out为加密混淆后输出jar文件(支持pom.xml中变量写法)。
节点配置要保留的类、方法、属性。
配置说明:对于protected 及以上的访问级别的类、方法、属性保持名称不变。
!com.xxx.xxx.* 非项目包下的类不混淆。
其中节点,表示忽略混淆的类,其下所有代码均不混淆;对于启动项目报错的类,配置到此处即可。
对于一个springboot项目此配置基本够用,其他配置,保持默认即可。

image

4、maven配置pom.xml
其他不变,在build>plugins节点内maven打包节点plugin后添加两个plugin节点
注意:若项目使用了${project.build.finalName}参数,在pom.xml中要配置。
若不是springboot项目,maven打包build节点可不配置,但${project.artifactId}节点要配置。
image
上图说明:将allatori.xml文件从根目录拷贝到target目录。
image
上图说明:${basedir}/../../lib/allatori.jar指定混淆组件allatori.jar地址。
${basedir}/target/allatori.xml指定使用的混淆配置文件,已从根目录下拷贝到target目录。
5、执行打包混淆,mvn clean package。输出文件为混淆后的jar包,在target目录下。例子中混淆后的包为project-xxx-xxx-obfuscated.jar,原始包project-xxx-xxx.jar
6、若有更多要求,如特殊打包环境启用混淆,可使用profiles方式,如添加一种prod环境,在打包时使用参数 prod,执行命令maven clean package -Pprod;不带有prod默认打包模式,不混淆。
若项目引用了其他加密混淆的项目,使用dependencies重新引用。
image

二、其他
1、扩展,上述打包如果子项目过多,可将加密混淆后的jar包,统一输出到一个指定目录。
2、不使用maven加密混淆,可参考下载包中的例子,直接执行命令打包混淆。
三、代码实例
以下为完整版代码,若要求比较简单请参考上面图片中代码。
1、allatori.xml 代码实例

 <config><!-- Maven properties could be used in Allatori configuration file. --><input><jar in="${obf.in.name}" out="${obf.out.name}"/></input><keep-names><class access="protected+"><field access="protected+"/><method access="protected+"/></class><class template="class !com.xxx.xxx.*"/><class template="class com.xxx.xxx.controller.*"><method access="protected+" parameters="keep"/></class></keep-names><ignore-classes><class template="class com.xxx.xxx.datascope.*.**"/></ignore-classes><!-- 水印 --><watermark key="secure-key-to-extract-watermark" value="@Copyright (c) by 2025-2099 Co.All Rights Reserved"/><!-- 随机字符加密 --><property name="random-seed" value="任意字符串"/><!-- 字符串加密 --><property name="string-encryption" value="maximum"/><!--    fast,strong--><property name="string-encryption-type" value="fast"/><property name="string-encryption-version" value="v4"/><!-- 成员重新排序 --><property name="member-reorder" value="random"/><!--    <property name="string-encryption-ignored-strings" value="patterns.txt"/>--><!-- 广泛流混淆 --><!-- Control flow obfuscation --><property name="control-flow-obfuscation" value="enable"/><property name="extensive-flow-obfuscation" value="normal"/><expiry date="2099/01/01" string="EXPIRED!"/><property name="log-file" value="log.xml"/>
</config>

2、pom.xml 代码实例。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>com.xxx</groupId><artifactId>xxx-modules</artifactId><version>0.0.0</version></parent><modelVersion>4.0.0</modelVersion><artifactId>xxx-modules-topic</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- 各种引用 --></dependencies><build><finalName>${project.artifactId}</finalName></build><profiles><profile><id>default</id><activation><activeByDefault>true</activeByDefault></activation><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><configuration><includeSystemScope>true</includeSystemScope></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></profile><!--若本项目引用了其他混淆的项目,使用此配置,加密打包 maven clean package -Pprod--><profile><id>prod</id><activation><activeByDefault>false</activeByDefault></activation><properties><obf.dir>obfuscated</obf.dir><obf.in.name-pre>${project.artifactId}-temp</obf.in.name-pre><obf.in.name>${obf.in.name-pre}.jar</obf.in.name><obf.out.name>${obf.dir}/${project.artifactId}-${project.version}.jar</obf.out.name></properties><!--重新加载混淆的依赖--><dependencies><dependency><groupId>com.xxx</groupId><artifactId>xxx-xxxxx-xxx</artifactId><version>${project.version}</version><scope>system</scope><systemPath>${basedir}/../xxx-common/xxx-common-module_1/target/${obf.dir}/xxx-common-module_1-${project.version}.jar</systemPath></dependency></dependencies><build><finalName>${obf.in.name-pre}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><configuration><includeSystemScope>true</includeSystemScope></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin><!-- Copying Allatori configuration file to 'target' directory.The destination file will be filtered (Maven properties used in configuration file will be resolved). --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><version>1.3</version><executions><execution><id>run-create-obf-dir</id><phase>package</phase><configuration><tasks><delete dir="${basedir}/target/${obf.dir}"/><mkdir dir="${basedir}/target/${obf.dir}"/></tasks></configuration><goals><goal>run</goal></goals></execution></executions></plugin><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}</directory><includes><include>allatori.xml</include></includes><filtering>true</filtering></resource></resources></configuration></execution></executions></plugin><!-- Running 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></plugins></build></profile></profiles></project>
http://www.gsyq.cn/news/28976.html

相关文章:

  • 2025年10月小红书代运营公司推荐榜:五强评测与选择策略
  • Bun v1.3 重磅发布:一站式全栈 JS 运行时,前端开发、数据库、Redis 全内置
  • 2025年10月中国丝绸选购榜:十家口碑排行全解析
  • 2025年10月益生菌品牌推荐:权威榜单对比全解析
  • 2025年10月种植牙医院排名:五强真实数据公开
  • Langflow:面向 AI Agent、API 与 LLM 的拖拽式流程构建工具
  • 权威调研榜单:环形导轨实力厂家TOP3榜单好评深度解析
  • 关于九州通WMS函数 SQL的相关保存表名
  • 基于PCIe3.0X16的的100G光纤采集存储设备
  • Java泛型符号T、E、K、V、? 傻傻分不清楚
  • 实用指南:小米投下语音AI“核弹”:MiMo-Audio开源,语音领域的“GPT-3时刻”来了
  • 换 Windows 新电脑?教你将旧电脑程序传输新电脑技巧
  • 2025 年低代码平台厂商最新推荐排行榜:深度解析行业实力与创新优势,助力企业精准选型
  • 智能时代下的SEO关键词优化新策略 - 实践
  • 2025 年集装袋厂家最新推荐榜单:全面剖析行业领军者创新工艺与卓越品质,精选导电 / 防静电 / 抗静电 / 铝箔 / 食品级等多类型产品优质厂家
  • P9356 「SiR-1」Bracket 做题记录
  • 基于Java+Springboot+Vue开发的鲜牛奶订购网站管理系统(前后端分离)源码+运行步骤
  • 2025年10月PE管厂家推荐榜:五强对比与选购全攻略
  • 安卓照片误删?这 5 种恢复方法亲测有效,小白也能上手
  • 示波器探头衰减怎么判断?3 种方法 + 常见问题,新手也能学会​
  • ORA-01033 : ORACLE initialization or shutdown in progress
  • 致敬1024,《手搓》轻量级EventBus
  • Docker镜像库配置
  • 2025年工作服厂家推荐排行榜,防静电/劳保/国网/餐厅/工厂/电工/防酸碱/电力/车间/航空/员工工作服,文化衫/t恤/polo衫/冲锋衣/t恤衫公司精选
  • 2025年10月销毁公司推荐:森蓝领衔服务榜对比
  • 2025年10月淡化痘印产品推荐对比:从色素代谢到修护通路全解析
  • 2025年10月上海装修公司对比榜:千州装饰等五强口碑解析
  • 2025年10月医美项目后用什么产品评测榜:术后舒缓精华口碑对比
  • 一些c语言特殊用法
  • sql server查看所有表名以及注释