SecureRandom sr = new SecureRandom();
byte[] bytes = new byte[8];
bytes = sr.generateSeed(8);
System.out.println(new String(Hex.encode(bytes)));
其中Hex.ecode使用的外部包
也可以使用下面这个
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp ;
}
}
return hs;
}