Java进行Base64的编码(Encode)与解码(Decode)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java进行Base64的编码(Encode)与解码(Decode)相关的知识,希望对你有一定的参考价值。

import java.util.Base64;

public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
                    // 要加密的字符串
                    String pwd = "12345678";
                    // 加密
                    String encodeToString = Base64.getEncoder().encodeToString(pwd.getBytes("UTF-8"));
                    System.out.println(encodeToString);// MTIzNDU2Nzg=
                    // 解密
                    String decodeToString = new String(Base64.getDecoder().decode(encodeToString.getBytes()), "UTF-8");
                    System.out.println(decodeToString);// 12345678
            }
}

以上是关于Java进行Base64的编码(Encode)与解码(Decode)的主要内容,如果未能解决你的问题,请参考以下文章