XJarSpring Boot JAR 安全加密運(yùn)行工具
XJar — Spring-Boot JAR 包加密運(yùn)行工具,避免源碼泄露以及反編譯。
Spring Boot JAR安全加密運(yùn)行工具,同時(shí)支持原生的JAR。
基于對(duì)JAR包內(nèi)資源的加密以及拓展ClassLoader來(lái)構(gòu)建的一套程序加密啟動(dòng),動(dòng)態(tài)解密運(yùn)行的方案,避免源碼泄露或反編譯。
功能特性
-
無(wú)需侵入代碼,只需要把編譯好的JAR包通過(guò)工具加密即可。
-
完全內(nèi)存解密,杜絕源碼以及字節(jié)碼泄露以及反編譯。
-
支持所有JDK內(nèi)置加解密算法。
-
可選擇需要加解密的字節(jié)碼或其他資源文件,避免計(jì)算資源浪費(fèi)。
環(huán)境依賴(lài)
JDK 1.7 +
使用步驟
<project> <!-- 設(shè)置 jitpack.io 倉(cāng)庫(kù) --> <repositories> <repository> <id>jitpack.io</id> <url>https://www.jitpack.io</url> </repository> </repositories> <!-- 添加 XJar 依賴(lài) --> <dependencies> <dependency> <groupId>com.github.core-lib</groupId> <artifactId>xjar</artifactId> <version>LATEST_VERSION</version> </dependency> </dependencies> </project>
// Spring-Boot Jar包加密
public static void main(String[] args) {
String password = "io.xjar";
File plaintext = new File("/path/to/read/plaintext.jar");
File encrypted = new File("/path/to/save/encrypted.jar");
XBoot.encrypt(plaintext, encrypted, password);
}
// Spring-Boot Jar包解密
public static void main(String[] args) {
String password = "io.xjar";
File encrypted = new File("/path/to/read/encrypted.jar");
File decrypted = new File("/path/to/save/decrypted.jar");
XBoot.decrypt(encrypted, decrypted, password);
}
// Jar包加密
public static void main(String[] args) {
String password = "io.xjar";
File plaintext = new File("/path/to/read/plaintext.jar");
File encrypted = new File("/path/to/save/encrypted.jar");
XJar.encrypt(plaintext, encrypted, password);
}
// Jar包解密
public static void main(String[] args) {
String password = "io.xjar";
File encrypted = new File("/path/to/read/encrypted.jar");
File decrypted = new File("/path/to/save/decrypted.jar");
XJar.decrypt(encrypted, decrypted, password);
}
// 命令行運(yùn)行JAR java -jar /path/to/encrypted.jar // 在提示輸入密碼的時(shí)候輸入密碼后按回車(chē)即可正常啟動(dòng),也可以通過(guò)傳參的方式直接啟動(dòng) java -jar /path/to/encrypted.jar --xjar.password=PASSWORD
參數(shù)說(shuō)明
-
--xjar.algorithm 加解密算法名稱(chēng),缺省為AES,支持JDK所有內(nèi)置算法,如AES / DES ...
-
--xjar.keysize 密鑰長(zhǎng)度,缺省為128,根據(jù)不同的算法選取不同的密鑰長(zhǎng)度。
-
--xjar.ivsize 向量長(zhǎng)度,缺省為128,根據(jù)不同的算法選取不同的向量長(zhǎng)度。
-
--xjar.password 密碼
進(jìn)階用法
// 只加密自身項(xiàng)目及相關(guān)模塊的源碼不加密第三方依賴(lài),可以通過(guò)XJarArchiveEntryFilter來(lái)定制需要加密的JAR包內(nèi)資源
public static void main(String[] args) {
String password = "io.xjar";
File plaintext = new File("/path/to/read/plaintext.jar");
File encrypted = new File("/path/to/save/encrypted.jar");
XBoot.encrypt(plaintext, encrypted, password, new XJarArchiveEntryFilter() {
@Override
public boolean filter(JarArchiveEntry entry) {
return entry.getName().startsWith("/BOOT-INF/classes/")
|| entry.getName().startsWith("/BOOT-INF/lib/jar-need-encrypted");
}
});
}
變更記錄
-
v1.0.5
-
支持并行類(lèi)加載,需要JDK1.7+的支持,可提升多線程環(huán)境類(lèi)加載的效率
-
Spring-Boot JAR 包加解密增加一個(gè)安全過(guò)濾器,避免無(wú)關(guān)資源被加密造成無(wú)法運(yùn)行
-
XBoot / XJar 工具類(lèi)中增加多個(gè)按文件路徑加解密的方法,提升使用便捷性
-
-
v1.0.4 小優(yōu)化
-
v1.0.3 增加Spring-Boot的FatJar加解密時(shí)的缺省過(guò)濾器,避免由于沒(méi)有提供過(guò)濾器時(shí)加密后的JAR包不能正常運(yùn)行。
-
v1.0.2 修復(fù)中文及空格路徑的問(wèn)題
-
v1.0.1 升級(jí)detector框架
-
v1.0.0 第一個(gè)正式版發(fā)布
