Skip to content

Commit

Permalink
修改密钥生成.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed May 14, 2024
1 parent b72273a commit d4f3c4c
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Random;

/**
* AES CBC模式加密工具类
Expand All @@ -32,6 +32,8 @@
*/
public class AES {

private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

/**
* 加密
*
Expand Down Expand Up @@ -100,10 +102,17 @@ public static String decrypt(String data, String key) {
/**
* 生成一个随机字符串密钥
*
* @return
* @throws NoSuchAlgorithmException
* @return 密钥
*/
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();
}

}

0 comments on commit d4f3c4c

Please sign in to comment.