[java8]~Base64(加密及java8使用方式)

簡介

Base64其實不是安全領域下的加密解密算法。
Base64只能算是一個編碼算法,對數據內容進行編碼來適合傳輸。

由於某些系統中只能使用ASCII字符。Base64就是用來將非ASCII字符的數據轉換成ASCII字符的一種方法。
而且Base64特別適合在http,mime協議下快速傳輸數據。

測試代碼

package com.qy.test.demo;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Test {

    public static void main(String[] args) {
        String text = "sUen(8&a";
        //編碼
        String encode = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
        System.out.println(encode);
        //解碼
        String dencode = new String(Base64.getDecoder().decode(encode),StandardCharsets.UTF_8);
        System.out.println(dencode);
    }

}

測試結果

c1Vlbig4JmE=
sUen(8&a
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章