一些常用的字符工具類方法

生成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);
		}
	}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章