刘韬 1 năm trước cách đây
mục cha
commit
4efe639343

+ 5 - 0
DataFusion/.classpath

@@ -25,5 +25,10 @@
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/okio-2.2.2.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/sqljdbc42.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfinal-4.8-bin-with-src.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bcpg-jdk18on-1.73.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bcpkix-jdk18on-1.73.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bcprov-jdk18on-1.73.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bouncy-gpg-2.3.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-codec-1.15.jar"/>
 	<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
 </classpath>

BIN
DataFusion/WebRoot/WEB-INF/lib/bcpg-jdk18on-1.73.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/bcpkix-jdk18on-1.73.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/bcprov-jdk18on-1.73.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/bouncy-gpg-2.3.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/commons-codec-1.15.jar


+ 8 - 2
DataFusion/src/com/zskk/service/DataService.java

@@ -18,7 +18,7 @@ import okhttp3.Response;
 
 public class DataService {
 	
-    private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
+    private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/ris_secret/getExam";
     
     private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
     
@@ -128,7 +128,13 @@ public class DataService {
     
     public static void main(String[] args) {
     	Map <String,String> map = new HashMap<String,String>();
-    	map.put("institution_id", "73090001");
+    	map.put("institution_id", "06300006");
+//    	map.put("num", "10");
+//    	map.put("createdAt", "2023-03-14 17:22:06,2023-03-14 17:22:06");
+//    	map.put("exam_status", "3,7,8,9");
+    	
+		System.out.println(JSON.toJSONString(map));
+
 //    	map.put("num", "10");
 		postWithParameters(GET_KEY_URL, map);
 	}

+ 122 - 0
DataFusion/src/com/zskk/tools/AESUtils.java

@@ -0,0 +1,122 @@
+package com.zskk.tools;
+
+import org.apache.commons.codec.binary.Base64;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+
+public class AESUtils {
+	/*
+     * 使用PKCS7Padding填充必须添加一个支持PKCS7Padding的Provider
+     * 类加载的时候就判断是否已经有支持256位的Provider,如果没有则添加进去
+     */
+    static {
+        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
+            Security.addProvider(new BouncyCastleProvider());
+        }
+    }
+
+    /**
+     * 加密 128位
+     *
+     * @param content 需要加密的原内容
+     * @param pkey    密匙
+     */
+    public static byte[] aesEncrypt(byte[] content, String pkey,String IV) {
+        try {
+            //SecretKey secretKey = generateKey(pkey);
+            //byte[] enCodeFormat = secretKey.getEncoded();
+            SecretKeySpec skey = new SecretKeySpec(pkey.getBytes(), "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");// "算法/加密/填充"
+            IvParameterSpec iv = new IvParameterSpec(IV.getBytes());
+//            cipher.init(Cipher.ENCRYPT_MODE, skey, iv);//初始化加密器
+            cipher.init(Cipher.ENCRYPT_MODE, skey);//初始化加密器
+
+            return cipher.doFinal(content);
+        } catch (Exception e) {
+            //System.out.println("aesEncrypt() method error:"+e.getLocalizedMessage());
+        }
+        return null;
+    }
+    /**
+     * 获得密钥
+     */
+    private static SecretKey generateKey(String secretKey) throws Exception {
+        //防止linux下 随机生成key
+        Provider p = Security.getProvider("SUN");
+        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG", p);
+        secureRandom.setSeed(secretKey.getBytes());
+        KeyGenerator kg = KeyGenerator.getInstance("AES");
+        kg.init(secureRandom);
+        // 生成密钥
+        return kg.generateKey();
+    }
+    /**
+     * @param content 加密前原内容
+     * @param pkey    长度为16个字符,128位
+     * @return base64EncodeStr   aes加密完成后内容
+     */
+    public static String aesEncryptStr(String content, String pkey,String IV) {
+        byte[] aesEncrypt = aesEncrypt(content.getBytes(StandardCharsets.UTF_8), pkey,IV);
+        return Base64.encodeBase64String(aesEncrypt);
+    }
+    /**
+     * @param content base64处理过的字符串
+     * @param pkey    密匙
+     * @return 解密 失败将返回NULL
+     */
+    public static String aesDecodeStr(String content, String pkey,String IV) throws Exception {
+        try {
+            byte[] base64DecodeStr = Base64.decodeBase64(content);
+            byte[] aesDecode = aesDecode(base64DecodeStr, pkey,IV);
+            if (aesDecode == null) {
+                return null;
+            }
+            return new String(aesDecode, StandardCharsets.UTF_8);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new Exception("解密异常");
+        }
+    }
+    /**
+     * 解密 128位
+     *
+     * @param content 解密前的byte数组
+     * @param pkey    密匙
+     * @return result  解密后的byte数组
+     */
+    public static byte[] aesDecode(byte[] content, String pkey,String IV) throws Exception {
+        //SecretKey secretKey = generateKey(pkey);
+        //byte[] enCodeFormat = secretKey.getEncoded();
+        SecretKeySpec skey = new SecretKeySpec(pkey.getBytes(), "AES");
+        IvParameterSpec iv = new IvParameterSpec(IV.getBytes(StandardCharsets.UTF_8));
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");// 创建密码器
+//        cipher.init(Cipher.DECRYPT_MODE, skey, iv);// 初始化解密器
+        cipher.init(Cipher.DECRYPT_MODE, skey);// 初始化解密器
+
+        return cipher.doFinal(content);
+    }
+    public static void main(String[] args) throws Exception {
+        //明文
+        String content = "3,7,8,9";
+        //默认向量常量
+        String IV = "0000000000000000";
+        //密匙
+        String pkey = "c552e6d332597f9efd3697fb76bb9cfb";
+        System.out.println("待加密报文:" + content);
+        System.out.println("密匙:" + pkey);
+        String aesEncryptStr = AESUtils.aesEncryptStr(content, pkey,IV);
+        System.out.println("加密报文:" + aesEncryptStr);
+        String aesDecodeStr = AESUtils.aesDecodeStr("uKvSxroUgmrGXBb41GcmiQ==", pkey,IV);
+        System.out.println("解密报文:" + aesDecodeStr);
+        System.out.println("加解密前后内容是否相等:" + aesDecodeStr.equals(content));
+    }
+
+}