天天看點

【Base64】Base64中的格式轉換

1. 參考表

【Base64】Base64中的格式轉換

2.demo:

package cn.com.infosec.netcert.caAdmin.test;

import java.text.ParseException;
import java.util.Base64;

/**   
 * @Author jy    
 * @Time 2019-07-15 20:06
 */
public abstract class Test_Base64 {

	public static void main(String[] args) throws ParseException {
		
		byte[] b1 = Base64.getEncoder().encode(new byte[]{'a','a','a'});
		String str_1 = new String(b1);
		System.out.println(str_1);  //編碼之後 : FWFh
		
		byte[] b2 = Base64.getDecoder().decode(b1);
		byte[] b3 = Base64.getDecoder().decode(str_1);

		System.out.println(new String(b2));	//解碼之後: aaa
		System.out.println(new String(b3)); //解碼之後: aaa
			
	}

}
           

3.byte[] 轉換為  Base64 編碼格式 過程詳解:

【Base64】Base64中的格式轉換

4. 總結