生成md5
public static String getMD5(String str) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(str.getBytes());
String md5 = bytes.toString();
return md5;
}
生成uuid
public static String getUUId() {
String uuid = UUID.randomUUID().toString();
String uuid2 = uuid.replaceAll("-", "");
return uuid2;
}
base64編碼和解碼
public static String decode(String str) {
try {
return new String(Base64.decode(str)).substring(0, 32);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String encode(String str) {
try {
String encode = Base64.encode(str.getBytes(CHAR_SET)).replace(NEW_LINE, "");
return encode.substring(0, 32);
} catch (Exception e) {
throw new RuntimeException(e);
}
}