package cn.huge.gateway.utils;
|
|
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
/**
|
* @title: 转码工具类
|
* @description: 需要对字符串Base64/MD5/SHA1/SHA256可直接调用此类方法实现
|
* @company: hugeinfo
|
* @author: liyj
|
* @time: 2021-11-05 16:51:48
|
* @version: 1.0.0
|
*/
|
public class EncryptionUtils {
|
|
public static void main( String[] args ) {
|
|
}
|
|
/**
|
* 对字符串Base64加密
|
* @param data 需要加密的字符串
|
* @return 返回字符串Base64加密后的字符串
|
*/
|
public static String base64Encode( String data ) {
|
return Base64.encodeBase64String( data.getBytes() );
|
}
|
|
/**
|
* 字符串Base64解密
|
* @param data 需要加密的字符串
|
* @return 返回解密后的字节数组
|
*/
|
public static byte[] base64Decode( String data ) {
|
return Base64.decodeBase64( data.getBytes() );
|
}
|
|
/**
|
* 对字符串进行MD5加密 此加密方法不可逆
|
* @param data 需要加密的字符串
|
* @return String
|
*/
|
public static String md5( String data ) {
|
return DigestUtils.md5Hex( data );
|
}
|
|
/**
|
* 对字符串进行SHA1加密
|
* @param data 需要加密的字符串
|
* @return String
|
*/
|
public static String sha1( String data ) {
|
return DigestUtils.shaHex( data );
|
}
|
|
/**
|
* 对字符串进行SHA256加密
|
* @param data 需要加密的字符串
|
* @return String
|
*/
|
public static String sha256Hex( String data ) {
|
return DigestUtils.sha256Hex( data );
|
}
|
}
|
/**
|
* -------------------_ooOoo_-------------------
|
* ------------------o8888888o------------------
|
* ------------------88" . "88------------------
|
* ------------------(| -_- |)------------------
|
* ------------------O\ = /O------------------
|
* ---------------____/`---'\____---------------
|
* -------------.' \\| |// `.-------------
|
* ------------/ \\||| : |||// \------------
|
* -----------/ _||||| -:- |||||- \-----------
|
* -----------| | \\\ - /// | |-----------
|
* -----------| \_| ''\---/'' | |-----------
|
* -----------\ .-\__ `-` ___/-. /-----------
|
* ---------___`. .' /--.--\ `. . __----------
|
* ------."" '< `.___\_<|>_/___.' >'"".-------
|
* -----| | : `- \`.;`\ _ /`;.`/ - ` : | |-----
|
* -----\ \ `-. \_ __\ /__ _/ .-` / /-----
|
* ======`-.____`-.___\_____/___.-`____.-'======
|
* -------------------`=---='
|
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
* ---------佛祖保佑---hugeinfo---永无BUG----------
|
*/
|