package com.nanyan.securitylink;
import java.security.SecureRandom;
public class RandomHS256KeyGenerator {
public static String generateRandomKey() {
SecureRandom secureRandom = new SecureRandom();
byte[] keyBytes = new byte[32];
secureRandom.nextBytes(keyBytes);
return bytesToHex(keyBytes);
}
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
public static void main(String[] args) {
String randomKey = generateRandomKey();
System.out.println("生成的随机 HS256 密钥: " + randomKey);
}
}
-
zhouwei authored7806733c