java:编写jar包加密工具,防止反编译
懒人方案
网盘:
链接:https://pan.baidu.com/s/1x4OB1IF2HZGgtLhd1Kr_AQ
提取码:glx7
网盘内是已生成可用工具,下载可以直接使用,使用前看一下READ.txt文件。
注意:此加密工具会把Class完全加密,jd-gui-1.4.0只能反编译出jar结构,但是看不到class文件源码!
Maven依赖
<?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">
<modelVersion>4.0.0</modelVersion> <groupId>com.zy.java</groupId>
<artifactId>Util</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>com.github.core-lib</groupId>
<artifactId>xjar</artifactId>
<version>v1.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.github.core-lib</groupId>
<artifactId>loadkit</artifactId>
<version>v1.0.0</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build> </project>
java代码
package com.zy.java; import io.xjar.XConstants;
import io.xjar.XKit;
import io.xjar.boot.XBoot;
import io.xjar.key.XKey;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.security.NoSuchAlgorithmException; public class Practice{ private static String password = "你的加密密码";
private static JButton openItem, saveItem;
private static FileDialog openDia, saveDia;// 定义“打开、保存”对话框
private static String filePathOld;//旧文件路径
private static String filePathNew;//新文件路径
private static String fileName;//文件名
static JFrame f = null;
static JTextField locationText, typeText; public static void main(String[] args) { int gap = 5;
f = new JFrame("加密程序");
ImageIcon icon = new ImageIcon("src\\images\\2.ico");
f.setIconImage(icon.getImage());// 给窗体设置图标方法
f.setSize(550, 310);
f.setLocation(200, 200);
f.setLayout(null); JPanel pInput = new JPanel();
pInput.setBounds(gap, gap, 520, 60);
pInput.setLayout(new GridLayout(2, 3, gap, gap)); JLabel location = new JLabel("JAR路径:");
locationText = new JTextField(10);
openItem = new JButton("选取");// 创建“打开"菜单项 JLabel type = new JLabel("保存路径:");
typeText = new JTextField(10);
saveItem = new JButton("选取");// 创建“保存"菜单项 openDia = new FileDialog(f, "打开", FileDialog.LOAD);
saveDia = new FileDialog(f, "保存", FileDialog.SAVE); JButton b = new JButton("生成"); pInput.add(location);
pInput.add(locationText);
pInput.add(openItem);
pInput.add(type);
pInput.add(typeText);
pInput.add(saveItem); //文本域
final JTextArea ta = new JTextArea();
ta.setLineWrap(true);
b.setBounds(220, 60 + 30, 80, 30);
ta.setBounds(gap, 80 + 60, 523, 120); f.add(pInput);
f.add(b);
f.add(ta);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true); myEvent();
//鼠标监听
b.addActionListener(new ActionListener() {
boolean checkedpass = true; public void actionPerformed(ActionEvent e) {
XKey xKey = null;
System.out.println(" --- : "+fileName);
String newPath = filePathNew+"\\"+fileName+"-xjar.jar";
String oldPath = filePathOld;
try {
xKey = XKit.key(password);
XBoot.encrypt(oldPath, newPath, xKey, XConstants.MODE_DANGER);
ta.append(" Success! ");
} catch (NoSuchAlgorithmException eg) {
eg.printStackTrace();
} catch (Exception eg) {
eg.printStackTrace();
}
checkedpass = true;
checkEmpty(locationText, "JAR路径");
checkEmpty(typeText, "保存路径"); if (checkedpass) {
String model = "加密jar包保存路径 :%s";
String result = String.format(model, newPath);
ta.setText("");
ta.append(result);
} } //检验是否为空
private void checkEmpty(JTextField tf, String msg) {
if (!checkedpass)
return;
String value = tf.getText();
if (value.length() == 0) {
JOptionPane.showMessageDialog(f, msg + " 不能为空");
tf.grabFocus();
checkedpass = false;
}
}
});
} //选取按钮监听
private static void myEvent() { // 选取监听
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openDia.setVisible(true);//显示打开文件对话框
String dirpath = openDia.getDirectory();//获取打开文件路径并保存到字符串中。
String Name = openDia.getFile();//获取打开文件名称并保存到字符串中
System.out.println(" --- : " + Name.split(".jar")[0]);
fileName = Name.split(".jar")[0];
filePathOld = dirpath+Name;
if (dirpath == null || Name == null)//判断路径和文件是否为空
return; locationText.setText(dirpath+Name);
}
}); // 选取监听
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showDialog(new JLabel(), "选择");
File file = chooser.getSelectedFile();
if (file == null) {
System.out.println(" 路径 :"+file.getAbsoluteFile().toString());
typeText.setText(file.getAbsoluteFile().toString());
filePathNew = file.getAbsoluteFile().toString();
}else{
System.out.println(" 路径 :"+file.getAbsoluteFile().toString());
typeText.setText(file.getAbsoluteFile().toString());
filePathNew = file.getAbsoluteFile().toString();
}
}
});
// 窗体关闭监听
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
代码先进行打包,Maven ——> clean ——> install


代码运行测试
选择jar文件,保存路径,点击生成即可。

下载exe生成器
1.
exe4j : https://www.apponic.com/phome/download/95409-2-1593674778-a86aa6a3165855674c85c5a9dc7c8dbb/
下载安装完成后,界面如图,
第一步完成注册,Name,Company随便填就是了,注册码:A-XVK258563F-1p4lv7mg7sav (网上很多啊,随便搜一个就行)

2.
点击 next ,勾选JAR in EXE

3.
点击 next ,填写打包后的 exe程序名称和保存路径

4.
点击 next ,设置程序方式,兼容系统64位


5.
点击 next ,添加jar包,选择运行的主类的main方法



6.
点击 next ,设置JDK运行版本

7.
复制jre,放到jre的空文件夹下:D:/jre/jre


8.
加载jre环境



9.
一直点 next ,等待安装完成。

10.
尝试运行exe文件


成功!!
如果报错 java.lang.NoClassDefFoundError: BOOT-INF/classes/com/**/java/**** (wrong name: com/**/java/****) 返回第5步修改启动类进行尝试。

java:编写jar包加密工具,防止反编译的更多相关文章
- Android(java)学习笔记157:使用Dexdump等工具进行反编译
使用Dex等工具进行反编译步骤: (1)首先找到Android软件安装包中的class.dex,把APK文件改名为".zip",然后解压缩其中的class.dex文件,这是Java ...
- Android(java)学习笔记100:使用Dexdump等工具进行反编译
使用Dex等工具进行反编译步骤: (1)首先找到Android软件安装包中的class.dex,把APK文件改名为".zip",然后解压缩其中的class.dex文件,这是Java ...
- java的jar打包工具的使用
java的jar打包工具的使用 java的jar是一个打包工具,用于将我们编译后的class文件打包起来,这里面主要是举一个例子用来说明这个工具的使用. 在C盘下的temp文件夹下面: ...
- java的jar包加密
由于项目要求(虽然我觉得代码没什么机密可言...),写好的jar包需要做一定加密处理 这里提供两种办法,一种奇葩,一种通用 1. 直接修改jar文件: 具体步骤: 在代码中插入一段不会运行的到的代码 ...
- 如何修改可运行Jar包,如何反编译Jar包
将可运行Jar包,反编译成项目,修改代码,再次编译,打包. 需要工具:jd-gui.myeclipse 具体步骤: 1.使用jd-gui打开原始的Jar包,选择File-->Save All ...
- 【转载】关于 .Net 逆向的那些工具:反编译篇
在项目开发过程中,估计也有人和我遇到过同样的经历:生产环境出现了重大Bug亟需解决,而偏偏就在这时仓库中的代码却不是最新的.在这种情况下,我们不能直接在当前的代码中修改这个Bug然后发布,这会导致更严 ...
- Java 操作jar包工具类以及如何快速修改Jar包里的文件内容
需求背景:写了一个实时读取日志文件以及监控的小程序,打包成了Jar包可执行文件,通过我们的web主系统上传到各个服务器,然后调用ssh命令执行.每次上传前都要通过解压缩软件修改或者替换里面的配置文件, ...
- 后端开发工具:反编译工具、VS插件、.NET Framework源码地址
再学习.工作中,开发免不了要使用第三方工具.今天介绍2款反编译工具 一.dnspy 免安装.免费.可调试.可修改重新编译dll 开源项目地址:https://github.com/0xd4d/dnSp ...
- IDEA工具实现反编译操作
1.File - Settings... 2.在搜索框中输入“byte” - 勾选 Java Byte code Decompiler选项 点击 OK 键 3.弹出重启IDEA的选择框 选择“rest ...
随机推荐
- python基础之pip、.pyc、三元运算、进制、一切皆对象、可变与不可变类型
一.pip(下载工具==yum) 1.重点(必须掌握的) 列出已安装的包 pip list 安装要安装的包 pip install xxx 安装特定版本 pip install django==1.1 ...
- CGI开发-(转自 jemofh159)
随着Internet技术的兴起,在嵌入式设备的管理与交互中,基于Web方式的应用成为目前的主流,这种程序结构也就是大家非常熟悉的B/S结构,即在嵌入式设备上运行一个支持脚本或CGI功能的Web服务器, ...
- FD_SET -(转自 kakaxia6337的专栏)
FD_ZERO,FD_ISSET这些都是套节字结合操作宏 看看MSDN上的select函数, 这是在select io 模型中的核心,用来管理套节字IO的,避免出现无辜锁定. int se ...
- JMicro微服务之超时&重试
JMicro是本人开发的基于Java实现的微服务框架,当前正式版本为0.0.3,并已发布到maven中央仓库.项目源码github:https://github.com/mynewworldyyl/j ...
- Java基础之第二章变量
1. 变量介绍 变量是程序的基本组成单位 概念 变量相当于内存中一个数据存储空间的表示,可以通过变量名可以访问到变量(值). 变量使用 声明变量 int a; 赋值 a = 20; public cl ...
- 使用指定源安装python包
对于经常需要按照那个python包的同学,外网下载比较慢的话,可以使用公司内部的镜像进行安装 eg: pip install django -i http://mirrors.***.com.cn/p ...
- (转)修改python默认排序方式
在Java中,自定义类可以通过继承comparable接口,重写compareTo方法来使用内置sort()函数来对自定义对象排序,我就在想Python中有没有类似的操作. 首先随便写个自定义类,比如 ...
- jquery 改变标签样式
jQuery改变标签的样式一般有3种 预置好class,然后通过jQuery改变元素的class名,使用的是addClass.removeClass 直接改变元素的css属性值,这种是通过添加styl ...
- 使用shell脚本循环处理文本
公司是使用puppet来进行配置管理, 某天修改完puppet后领导回复: 我们有一个文档cabinet.txt记录了物理机器所在的机柜, 除了文档里的其他机器都是虚拟机或云服务器, 对虚拟机的pup ...
- GPU上的基本线性代数
GPU上的基本线性代数 cuBLAS库提供了基本线性代数子例程(BLAS)的GPU加速实现.cuBLAS通过针对NVIDIA GPU进行了高度优化的嵌入式行业标准BLAS API来加速AI和HPC应用 ...