对jar或者war进行加密解密
whycxzp
2021-12-22 f6b935781bcb43faea7aa894ce3a55873769efb3
beale-core/src/main/java/com/whyc/CoreAgent.java
@@ -6,6 +6,7 @@
import java.io.Console;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.nio.charset.Charset;
/**
@@ -32,7 +33,8 @@
        char[] pwd;
        //读取jar隐藏的密码,无密码启动模式(jar)
        pwd = JarDecryptor.readPassFromJar(new File(JarUtils.getRootPath(null)));
        //pwd = JarDecryptor.readPassFromJar(new File(JarUtils.getRootPath(null)));
        pwd = JarDecryptor.readPassFromJar2(new File(JarUtils.getRootPath(null)));
        if (args != null) {
            options.parse(args.split(" "));
@@ -94,15 +96,22 @@
        }
        //验证密码,jar包是才验证
        byte[] passHash = JarDecryptor.readEncryptedFile(new File(JarUtils.getRootPath(null)), Const.CONFIG_PASSHASH);
        /*System.out.println("验证jar,密码路径"+JarUtils.getRootPath(null));
        byte[] passHash = JarDecryptor.readEncryptedFile2(new File(JarUtils.getRootPath(null)),Const.FILE_NAME2);
        if (passHash != null) {
            char[] p1 = StrUtils.toChars(passHash);
            char[] p1 = StrUtils.merger(pwd, EncryptUtils.SALT);
            char[] p2 = EncryptUtils.md5(StrUtils.merger(pwd, EncryptUtils.SALT));
            p2 = EncryptUtils.md5(StrUtils.merger(EncryptUtils.SALT, p2));
            if (!StrUtils.equal(p1, p2)) {
                Log.println("\nERROR: Startup failed, invalid password.\n");
                System.exit(0);
            }
        }*/
        byte[] pwdHash = JarDecryptor.readEncryptedFile2(new File(JarUtils.getRootPath(null)),Const.FILE_NAME2);
        if (pwdHash != null) {
            String pwdTrue = EncryptUtils.deAES(new String(pwdHash, Charset.forName("utf-8")), Const.AES_KEY.toCharArray());
            pwdTrue = pwdTrue.replace(" ","").replace(",","").replace("[","").replace("]","");
            pwd = pwdTrue.toCharArray();
        }
        //GO
@@ -162,4 +171,8 @@
        }
        return pwd;
    }
    public static void main(String[] args) {
        char[] chars = JarDecryptor.readPassFromJar(new File(JarUtils.getRootPath(null)));
    }
}