public String secureRandom(int length) {
byte[] bytes = new byte[length];
SecureRandom secureRandom = new SecureRandom();
secureRandom.nextBytes(bytes);
StringBuilder builderByte = new StringBuilder(length*2);
for(byte b: bytes) {
String hex = Integer.toHexString(b & 0xFF);
if(hex.length() < 2) {
hex = "0" + hex;
}
buliderByte.aooend(hex);
}
return builderByte.toString().toUpperCase(Locale.getDefault());
}
Java创建安全随机数
最新推荐文章于 2024-09-08 10:40:56 发布