SecureRandom sr = new SecureRandom();
byte[] bytes = new byte[8];
bytes = sr.generateSeed(8);
System.out.println(new String(Hex.encode(bytes)));

 其中Hex.ecode使用的外部包

也可以使用下面这个

 1 public static String byte2hex(byte[] b) {
 2         String hs = "";
 3         String stmp = "";
 4         for (int n = 0; n < b.length; n++) {
 5             stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
 6             if (stmp.length() == 1) {
 7                 hs = hs + "0" + stmp;
 8             } else {
 9                 hs = hs + stmp ;
10             }
11         }
12         return hs;
13     }

 

相关文章:

  • 2021-11-13
  • 2021-06-24
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2021-11-15
  • 2021-08-27
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
相关资源
相似解决方案