From 1ffbaa7b82f99443d933b0f7d0add0b35d2db01c Mon Sep 17 00:00:00 2001
From: wangrenhuang <wangren_huang@163.com>
Date: 星期三, 02 三月 2022 14:26:53 +0800
Subject: [PATCH] PTEncryptionUti新增解密方法

---
 src/main/java/com/hx/mybatis/aes/springbean/VariableAesKey.java |  124 +++++++++++++++++++++++++++++++----------
 1 files changed, 93 insertions(+), 31 deletions(-)

diff --git a/src/main/java/com/hx/mybatis/aes/springbean/VariableAesKey.java b/src/main/java/com/hx/mybatis/aes/springbean/VariableAesKey.java
index 835cb5e..e3f8fa2 100644
--- a/src/main/java/com/hx/mybatis/aes/springbean/VariableAesKey.java
+++ b/src/main/java/com/hx/mybatis/aes/springbean/VariableAesKey.java
@@ -3,6 +3,8 @@
 import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
 import com.hx.common.annotations.MysqlHexAes;
 import com.hx.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
@@ -11,15 +13,21 @@
 import java.io.FileFilter;
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.net.JarURLConnection;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.util.*;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
 /**
  * 鑾峰彇鎸囧畾鍖呴噷闈㈢殑AES绉橀挜
  */
 @Component
 public class VariableAesKey {
+
+    //log4j鏃ュ織
+    private static Logger logger = LoggerFactory.getLogger(VariableAesKey.class.getName());
 
     @Resource
     private ConstantBean constantBean;
@@ -34,6 +42,10 @@
 
     /**鍥哄畾鐨刟es绉橀挜*/
     public static String AES_KEY = null;
+    /**鏁版嵁搴撳姞瀵嗗瓧娈靛垵濮嬪寲鐗堟湰鍙�*/
+    public static String INIT_VERSION = null;
+
+
 
     /**瀛樺偍AES绉橀挜*/
     public static void setAesKey(String aesKeyFild,String aesKey){
@@ -59,21 +71,23 @@
 
         isRun = 1;
         //椤圭洰鍚姩鐨勬椂鍊欏~鍏�
-        System.err.println("鎵弿鑾峰彇AES:" + constantBean.getPackPath());
+        logger.info("鎵弿鑾峰彇AES鐨勫寘:" + constantBean.getPackPath());
         AES_KEY = constantBean.getFixedAesKey();
-        if(StringUtils.noNull(constantBean.getPackPath())){
+        INIT_VERSION = constantBean.getInitVersion();
+        if(!StringUtils.isEmpty(constantBean.getPackPath())){
             Set<Class<?>> classes = classData(constantBean.getPackPath());
-
+            logger.info("鎵弿鑾峰彇AES鐨勫寘classes:" + classes.size());
             Map<String,String> aesKeysFild = new HashMap<>();
             boolean isAes = false;
             String tableName = null;
 
             for(Class<?> cl:classes){
                 //琛ㄥ悕绉�
-                Table table = cl.getAnnotation(Table.class);
-                if(table == null){
+                boolean hasAnnotation = cl.isAnnotationPresent(Table.class);
+                if(!hasAnnotation){
                     continue;
                 }
+                Table table = cl.getAnnotation(Table.class);
                 tableName = table.name();
 
                 aesKeysFild = new HashMap<>();
@@ -84,7 +98,7 @@
                 fields = getPatentFields(fields,cl);
                 for (Field field:fields) {
                     // 鍒ゆ柇鏂规硶涓槸鍚︽湁鎸囧畾娉ㄨВ绫诲瀷鐨勬敞瑙�
-                    boolean hasAnnotation = field.isAnnotationPresent(MysqlHexAes.class);
+                    hasAnnotation = field.isAnnotationPresent(MysqlHexAes.class);
                     if (hasAnnotation) {
                         // 鏍规嵁娉ㄨВ绫诲瀷杩斿洖鏂规硶鐨勬寚瀹氱被鍨嬫敞瑙�
                         MysqlHexAes mysqlHexAes = field.getAnnotation(MysqlHexAes.class);
@@ -121,37 +135,85 @@
 
     /**鑾峰彇鍖呬笅闈㈢殑鎵�鏈夋枃浠�*/
     public static Set<Class<?>> classData(String packPath){
-        Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
+        Set<Class<?>> classes = new LinkedHashSet();
+        String[] split = packPath.split(",|;");
+        String[] var3 = split;
+        int var4 = split.length;
 
-        //鎴彇
-        String[] packPaths = packPath.split(";|,");
-        for( String packageName : packPaths){
-            // 鏄惁寰幆杩唬
+        label82:
+        for(int var5 = 0; var5 < var4; ++var5) {
+            String pack = var3[var5];
             boolean recursive = true;
-            // 鑾峰彇鍖呯殑鍚嶅瓧 骞惰繘琛屾浛鎹�
-            String packageDirName = packageName.replace('.', '/');
-            // 瀹氫箟涓�涓灇涓剧殑闆嗗悎 骞惰繘琛屽惊鐜潵澶勭悊杩欎釜鐩綍涓嬬殑things
-            Enumeration<URL> dirs;
-            try{
-                dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
-                // 寰幆杩唬涓嬪幓
-                while (dirs.hasMoreElements()){
-                    // 鑾峰彇涓嬩竴涓厓绱�
-                    URL url = dirs.nextElement();
-                    // 寰楀埌鍗忚鐨勫悕绉�
-                    String protocol = url.getProtocol();
-                    // 濡傛灉鏄互鏂囦欢鐨勫舰寮忎繚瀛樺湪鏈嶅姟鍣ㄤ笂
-                    if ("file".equals(protocol)) {
-                        // 鑾峰彇鍖呯殑鐗╃悊璺緞
-                        String filePath = URLDecoder.decode(url.getFile(), "UTF-8");
-                        // 浠ユ枃浠剁殑鏂瑰紡鎵弿鏁翠釜鍖呬笅鐨勬枃浠� 骞舵坊鍔犲埌闆嗗悎涓�
-                        findAndAddClassesInPackageByFile(packageName, filePath, recursive, classes);
+            String packageName = pack;
+            String packageDirName = pack.replace('.', '/');
+
+            try {
+                Enumeration dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
+
+                while(true) {
+                    label75:
+                    while(true) {
+                        if (!dirs.hasMoreElements()) {
+                            continue label82;
+                        }
+
+                        URL url = (URL)dirs.nextElement();
+                        String protocol = url.getProtocol();
+                        if ("file".equals(protocol)) {
+                            System.err.println("file绫诲瀷鐨勬壂鎻�:" + pack);
+                            String filePath = URLDecoder.decode(url.getFile(), "UTF-8");
+                            findAndAddClassesInPackageByFile(packageName, filePath, recursive, classes);
+                        } else if ("jar".equals(protocol)) {
+                            System.err.println("jar绫诲瀷鐨勬壂鎻�");
+
+                            try {
+                                JarFile jar = ((JarURLConnection)url.openConnection()).getJarFile();
+                                Enumeration entries = jar.entries();
+
+                                while(true) {
+                                    JarEntry entry;
+                                    String name;
+                                    int idx;
+                                    do {
+                                        do {
+                                            if (!entries.hasMoreElements()) {
+                                                continue label75;
+                                            }
+
+                                            entry = (JarEntry)entries.nextElement();
+                                            name = entry.getName();
+                                            if (name.charAt(0) == '/') {
+                                                name = name.substring(1);
+                                            }
+                                        } while(!name.startsWith(packageDirName));
+
+                                        idx = name.lastIndexOf(47);
+                                        if (idx != -1) {
+                                            packageName = name.substring(0, idx).replace('/', '.');
+                                        }
+                                    } while(idx == -1 && !recursive);
+
+                                    if (name.endsWith(".class") && !entry.isDirectory()) {
+                                        String className = name.substring(packageName.length() + 1, name.length() - 6);
+
+                                        try {
+                                            classes.add(Class.forName(packageName + '.' + className));
+                                        } catch (ClassNotFoundException var20) {
+                                            var20.printStackTrace();
+                                        }
+                                    }
+                                }
+                            } catch (IOException var21) {
+                                var21.printStackTrace();
+                            }
+                        }
                     }
                 }
-            }catch (IOException e){
-                e.printStackTrace();
+            } catch (IOException var22) {
+                var22.printStackTrace();
             }
         }
+
         return classes;
     }
 

--
Gitblit v1.8.0