废话少说,上代码:
public String generateToken(){
String tokenString = System.currentTimeMillis() + "" + new Random().nextInt(99999);
try {
MessageDigest mDigest = MessageDigest.getInstance("md5");
byte[] md5 = mDigest.digest(tokenString.getBytes());
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(md5);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}