base64加解密示例

import org.apache.tomcat.util.codec.binary.Base64;

public class Base64Coded {
    public static void main(String[] args) {
        String string = "张三";
        //编码
        String encode = encode(string.getBytes());
        System.out.println(string + "	编码后的字符串为:" + encode);
        //解码
        String decode = decode(encode.getBytes());
        System.out.println(encode + "	字符串解码后为:" + decode);
    }
    //base64 解码
    public static String decode(byte[] bytes) {
        return new String(Base64.decodeBase64(bytes));
    }

    //base64 编码
    public static String encode(byte[] bytes) {
        return new String(Base64.encodeBase64(bytes));
    }
    
}

结果:

张三 编码后的字符串为:5byg5LiJ
5byg5LiJ 字符串解码后为:张三
原文地址:https://www.cnblogs.com/nastu/p/15224091.html