瀏覽代碼

修改密钥生成.

https://github.com/baomidou/mybatis-plus/issues/6162
nieqiurong 1 年之前
父節點
當前提交
d4f3c4cbc6
共有 1 個文件被更改,包括 13 次插入4 次删除
  1. 13 4
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/AES.java

+ 13 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/AES.java

@@ -21,8 +21,8 @@ import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 import javax.crypto.spec.SecretKeySpec;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
-import java.security.NoSuchAlgorithmException;
 import java.util.Base64;
 import java.util.Base64;
+import java.util.Random;
 
 
 /**
 /**
  * AES CBC模式加密工具类
  * AES CBC模式加密工具类
@@ -32,6 +32,8 @@ import java.util.Base64;
  */
  */
 public class AES {
 public class AES {
 
 
+    private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
     /**
     /**
      * 加密
      * 加密
      *
      *
@@ -100,10 +102,17 @@ public class AES {
     /**
     /**
      * 生成一个随机字符串密钥
      * 生成一个随机字符串密钥
      *
      *
-     * @return
-     * @throws NoSuchAlgorithmException
+     * @return 密钥
      */
      */
     public static String generateRandomKey() {
     public static String generateRandomKey() {
-        return IdWorker.get32UUID().substring(0, 16);
+        Random random = new Random();
+        StringBuilder buffer = new StringBuilder();
+        int keySize = 16;
+        int length = CHARS.length();
+        while (keySize-- != 0) {
+            buffer.append(CHARS.charAt(random.nextInt(length)));
+        }
+        return buffer.toString();
     }
     }
+
 }
 }