package com.thhy.general.utils.password;
|
|
import com.thhy.general.common.BasicStatus;
|
import com.thhy.general.exception.BasicException;
|
import org.apache.commons.codec.DecoderException;
|
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Hex;
|
|
import java.io.UnsupportedEncodingException;
|
|
/**
|
* @Author: zhang_xiao_bo
|
* @Date: 2022/3/22 13:40
|
* @description:
|
*/
|
public class Encodes {
|
|
private static final String DEFAULT_URL_ENCODING = "UTF-8";
|
private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
|
/**
|
* Hex编码.
|
*/
|
public static String encodeHex(byte[] input) {
|
return new String(Hex.encodeHex(input));
|
}
|
|
/**
|
* Hex解码.
|
*/
|
public static byte[] decodeHex(String input) {
|
try {
|
return Hex.decodeHex(input.toCharArray());
|
} catch (DecoderException e) {
|
throw new BasicException(BasicStatus.ERROR);
|
}
|
}
|
|
/**
|
* Base64编码.
|
*/
|
public static String encodeBase64(byte[] input) {
|
return new String(Base64.encodeBase64(input));
|
}
|
|
/**
|
* Base64编码.
|
*/
|
public static String encodeBase64(String input) {
|
try {
|
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
|
} catch (UnsupportedEncodingException e) {
|
return "";
|
}
|
}
|
|
}
|