|
@@ -1,8 +1,12 @@
|
|
|
package com.szwl.util;
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+
|
|
|
+import java.security.SecureRandom;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Base64;
|
|
|
|
|
|
public class TimezoneFmtUtil {
|
|
|
|
|
@@ -13,6 +17,12 @@ public class TimezoneFmtUtil {
|
|
|
|
|
|
// String nowDateUTC = getNowDateUTC();
|
|
|
// System.out.println("nowDateUTC >>> " + nowDateUTC);
|
|
|
+
|
|
|
+ // 生成一个24字节长度的随机密钥
|
|
|
+ String key = generateKey(24);
|
|
|
+
|
|
|
+ // 输出生成的密钥
|
|
|
+ System.out.println("Generated Key: " + key);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -33,6 +43,20 @@ public class TimezoneFmtUtil {
|
|
|
return formatted;
|
|
|
}
|
|
|
|
|
|
+ public static String generateKey(int length) {
|
|
|
+ // 创建一个安全的随机数生成器
|
|
|
+ SecureRandom secureRandom = new SecureRandom();
|
|
|
+
|
|
|
+ // 创建一个字节数组,长度为指定的字节数
|
|
|
+ byte[] randomBytes = new byte[length];
|
|
|
+
|
|
|
+ // 填充随机字节
|
|
|
+ secureRandom.nextBytes(randomBytes);
|
|
|
+
|
|
|
+ // 将字节数组编码为Base64字符串
|
|
|
+ return Base64.getEncoder().encodeToString(randomBytes);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取中国时区的UTC格式
|