个人常用工具类 — Base64Utli
public class Base64Utile {
private static Logger LOGGER = LoggerFactory.getLogger(Base64Utile.class);
public static String getBase64(String str) {
if (StringUtil.isNull(str)) {
return str;
}
byte[] b = null;
String s = null;
try {
b = str.getBytes("utf-8");
byte[] encodeBase64 = Base64.encodeBase64(b);
s = new String(encodeBase64);
} catch (Exception e) {
LOGGER.error("加密异常", e);
}
return s;
}
public static String getFromBase64(String str) {
if (StringUtil.isNull(str)) {
return str;
}
byte[] b = null;
String result = null;
try {
b = Base64.decodeBase64(str);
result = new String(b, "utf-8");
} catch (Exception e) {
LOGGER.error("解密异常", e);
}
return result;
}
}