JDK1.8 下
package com.hs.order.util;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
public class Base64Util {
final static Base64.Decoder decoder = Base64.getDecoder();
final static Base64.Encoder encoder = Base64.getEncoder();
//解码
public static String getDecode(String text){
byte[] textByte;
try {
textByte = text.getBytes("UTF-8");
return new String(decoder.decode(textByte), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
//编码
public static String getEncode(String text){
byte[] textByte;
try {
textByte = text.getBytes("UTF-8");
return encoder.encodeToString(textByte);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
}