java安全令牌生成器
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 }
如果有使用请标明来源:http://www.cnblogs.com/duwenlei/