欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學堂Java培訓之使用Base64編碼實例源碼詳解

2019-04-26 14:23:10 2943瀏覽

今天扣丁學堂Java培訓老師給大家詳細介紹一下關(guān)于java使用Base64編碼實例詳解,下面我們一起來看一下吧。



TestBase64

package com.weiwen.provider.utils;
import java.io.IOException;
 
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
 
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
@Slf4j
public class Base64 {
 
  @Test
  public void testBase64() throws IOException {
   // BASE64編碼
   String s = "1f2bc1970a2eb19aabc0f94acea922717a1ae998603ff0593baff";
   BASE64Encoder encoder = new BASE64Encoder();
   s = encoder.encode(s.getBytes("UTF-8"));
//   System.out.println(s);
   log.info("BASE64編碼為:{}", JSON.toJSONString(s));
 
   // BASE64解碼
   BASE64Decoder decoder = new BASE64Decoder();
   byte[] bytes = decoder.decodeBuffer(s);
//   System.out.println(new String(bytes, "UTF-8"));
   log.info("BASE64解碼為:{}", JSON.toJSONString(new String(bytes, "UTF-8")));
  }
 }

Base64工具類

package com.weiwen.provider.utils;
import java.io.IOException;
 
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
 
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
@Slf4j
public class Base64 {
 
 
 /**
  * Base64 編碼
  * @param encodeText
  * @return
  * @throws IOException
  */
 public static String base64Encode(String encodeText) throws IOException{
  BASE64Encoder encoder = new BASE64Encoder();
  String str = encoder.encode(encodeText.getBytes("UTF-8"));
  log.info("BASE64編碼為:{}", JSON.toJSONString(str));
  return str;
 }
 
 
 /**
  * Base64 解碼
  * @param decodeText
  * @return
  * @throws IOException
  */
 public static byte[] base64Decode(String decodeText) throws IOException{
   BASE64Decoder decoder = new BASE64Decoder();
   byte[] bytes = decoder.decodeBuffer(decodeText);
   log.info("BASE64解碼為:{}", JSON.toJSONString(new String(bytes, "UTF-8")));
   return bytes;
 }
 
}

以上所述是小編給大家介紹的java使用Base64編碼詳解整合,希望對大家有所幫助,請關(guān)注扣丁學堂Java培訓官網(wǎng)、微信等平臺,扣丁學堂IT職業(yè)在線學習教育有專業(yè)的Java講師為您指導,此外扣丁學堂老師精心推出的Java視頻教程定能讓你快速掌握Java從入門到精通開發(fā)實戰(zhàn)技能??鄱W堂Java技術(shù)交流群:850353792。


扣丁學堂微信公眾號                          Python全棧開發(fā)爬蟲人工智能機器學習數(shù)據(jù)分析免費公開課直播間


      【關(guān)注微信公眾號獲取更多學習資料】         【掃碼進入Python全棧開發(fā)免費公開課】



查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>

標簽: Java培訓 Java視頻教程 Java多線程 Java面試題 Java學習視頻 Java開發(fā)

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部