he2802 2 年之前
父節點
當前提交
b5260833c5

+ 2 - 2
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -554,22 +554,22 @@ public class CommonController extends BaseController {
 
     @ApiOperation("学时抽查加密")
     @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
-    @Log(title = "学时抽查加密", businessType = BusinessType.INSERT)
     @PostMapping("/common/free/encryptDes")
     public AjaxResult encryptDes(@RequestBody ClassGradeDecryptQueryBo bo) {
         try{
             byte[] Keys = new byte[]{0x22, 0x34, 0x76, 0x58, (byte) 0x90, (byte) 0xAB, (byte) 0xAD, (byte) 0xBF};
             byte[] rgbKey = "0ca175b9c0f726a831d895e26933246".substring(0, 8).getBytes("UTF-8");
             String source = "bh="+bo.getBh()+"&idnum="+bo.getIdnum()+"&datetime=20230627";
+            System.out.println(source);
             return AjaxResult.success(ToolsUtils.encryptDesNew(source,"0ca175b9c0f726a831d895e26933246".substring(0, 8)));
         }catch (Exception e){
+            System.out.println(e.getMessage());
             return null;
         }
     }
 
     @ApiOperation("学时抽查解密")
     @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
-    @Log(title = "学时抽查解密", businessType = BusinessType.INSERT)
     @PostMapping("/common/free/dncryptDes")
     public AjaxResult dncryptDes(@RequestBody ClassGradeDecryptQueryBo bo) {
         try{

+ 68 - 14
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -15,6 +15,9 @@ import net.sf.jsqlparser.expression.LongValue;
 
 import javax.crypto.Cipher;
 import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import javax.crypto.spec.DESedeKeySpec;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 import java.awt.image.BufferedImage;
@@ -531,16 +534,19 @@ public class ToolsUtils {
         return new String(decryptedByteArray, StandardCharsets.UTF_8);
     }
 
-    public static String encryptDesNew(String source, String pass) throws Exception {
+    /*public static String encryptDesNew(String source, String pass) throws Exception {
         byte[] rgbKey = pass.getBytes("UTF-8");
         byte[] rgbIV = pass.getBytes("UTF-8");
-        Cipher cipher = Cipher.getInstance("DES");
-        SecretKeySpec keySpec = new SecretKeySpec(rgbKey, "DES");
-        IvParameterSpec ivSpec = new IvParameterSpec(rgbIV); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
-        byte[] inputByteArray = source.getBytes("UTF-8");
-        byte[] encryptedByteArray = cipher.doFinal(inputByteArray);
-        return Base64.getEncoder().encodeToString(encryptedByteArray);
-    }
+                DESedeKeySpec desKeySpec = new DESedeKeySpec(rgbKey);
+             SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+             SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
+             Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
+            byte[] inputByteArray = source.getBytes("UTF-8");
+            IvParameterSpec ivParameterSpec = new IvParameterSpec(rgbIV);
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec);
+            byte[] encrypted = cipher.doFinal(inputByteArray);
+            return Base64.getEncoder().encodeToString(encrypted);}
+    }*/
 
     /**
 
@@ -548,16 +554,64 @@ public class ToolsUtils {
      @param source 源字符串
      @param pass 密钥,长度必须8位
      @return 解密后的字符串 */
-    public static String decryptDesNew(String source, String pass) throws Exception {
+    /*public static String decryptDesNew(String source, String pass) throws Exception {
         byte[] rgbKey = pass.getBytes("UTF-8");
         byte[] rgbIV = pass.getBytes("UTF-8");
-        Cipher cipher = Cipher.getInstance("DES");
-        SecretKeySpec keySpec = new SecretKeySpec(rgbKey, "DES");
-        IvParameterSpec ivSpec = new IvParameterSpec(rgbIV);
-        cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
+        DESedeKeySpec desKeySpec = new DESedeKeySpec(rgbKey);
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
+        Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding")) {
+        byte[] inputByteArray = Base64.getDecoder().decode(source);
+        IvParameterSpec ivParameterSpec = new IvParameterSpec(rgbIV);
+        cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
+        byte[] decrypted = cipher.doFinal(inputByteArray);
+        return new String(decrypted, "UTF-8");
+        }
+    }*/
+
+
+ public static String encryptDesNew(String source, String pass) throws Exception {
+        byte[] rgbKey = pass.getBytes(StandardCharsets.UTF_8);
+        byte[] rgbIV = pass.getBytes(StandardCharsets.UTF_8);
+        DESKeySpec desKeySpec = new DESKeySpec(rgbKey);
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
+        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
+        byte[] inputByteArray = source.getBytes(StandardCharsets.UTF_8);
+        IvParameterSpec ivParameterSpec = new IvParameterSpec(rgbIV);
+        cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec);
+        byte[] encryptedByteArray = cipher.doFinal(inputByteArray);
+        return Base64.getEncoder().encodeToString(encryptedByteArray);
+    }
+
+   public static String decryptDesNew(String source, String pass) throws Exception {
+        byte[] rgbKey = pass.getBytes(StandardCharsets.UTF_8);
+        byte[] rgbIV = pass.getBytes(StandardCharsets.UTF_8);
+        DESKeySpec desKeySpec = new DESKeySpec(rgbKey);
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
+        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
         byte[] inputByteArray = Base64.getDecoder().decode(source);
+        IvParameterSpec ivParameterSpec = new IvParameterSpec(rgbIV);
+        cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
         byte[] decryptedByteArray = cipher.doFinal(inputByteArray);
-        return new String(decryptedByteArray, "UTF-8");
+        return new String(decryptedByteArray, StandardCharsets.UTF_8);
+    }
+
+    private static String base64Encode(byte[] bytes) throws IOException {
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        Base64.getEncoder().wrap(output).write(bytes);
+        return output.toString(StandardCharsets.UTF_8.name());
+    }
+
+    /*private static byte[] base64Decode(String str) throws IOException {
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        Base64.getDecoder().wrap(output).write(str.getBytes(StandardCharsets.UTF_8));
+        return output.toByteArray();
+    }*/
+    private static byte[] base64Decode(String str) throws IOException {
+        byte[] decodedString = Base64.getDecoder().decode(new String(str).getBytes("UTF-8"));
+        return decodedString;
     }
 
 }

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/ClassGradeUserServiceImpl.java

@@ -669,6 +669,7 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
             classGradeUser = iClassGradeUserService.getOne(new LambdaQueryWrapper<ClassGradeUser>().eq(ClassGradeUser::getGradeId, classGrade.getGradeId()).eq(ClassGradeUser::getUserId, user.getUserId()).last("limit 1"));
             if (Validator.isNotEmpty(classGradeUser)) {
                 grade = classGrade;
+                break;
             }
         }
         if (Validator.isEmpty(classGradeUser)) {