这个方法是Java 1.8 的,自动导入的Jar包是java.util.Base64
1.解码
public String decode(String s)
{
String decoded= null;
try
{
byte [] barr = Base64.getDecoder().decode(s.getBytes()); //获取到s的字节码,传入进去
decoded= new String(barr, "utf-8");//转码后的字节码转换成String类型,这里字节码就是起到桥接的作用
} catch (Exception e)
{
e.printStackTrace();
}
return decoded;
}
2.编码
String encoded= Base64.getEncoder().encodeToString(s.getBytes());