Base64

Posted refresh-air

tags:

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

从JDK 1.8开始,就提供了java.util.Base64.Decoder和java.util.Base64.Encoder的JDK公共API,可代替sun.misc.BASE64Decoder和sun.misc.BASE64Encoder的JDK内部API

 

 /**
     * BASE64 加密
     * 
     * @param data
     *            要加密的数据
     * @return 加密后的字符串
     */
    public static String encryptBASE64(byte[] data) 
        Encoder encoder = Base64.getEncoder();
        String encode = encoder.encodeToString(data);
        return encode;
    
    /**
     * BASE64  解密
     * 
     * @param data
     *            要解密的字符串
     * @return 解密后的byte[]
     * @throws Exception
     */
    public static byte[] decryptBASE64(String data) throws Exception 
        Decoder decoder = Base64.getDecoder();
        byte[] buffer = decoder.decode(data);
        return buffer;
    

  

以上是关于Base64的主要内容,如果未能解决你的问题,请参考以下文章