最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java使用Base64編碼實例

 更新時間:2019年03月13日 09:56:57   作者:男人要霸氣  
這篇文章主要介紹了java使用Base64編碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本文實例為大家分享了java使用Base64編碼的具體代碼,供大家參考,具體內(nèi)容如下

Test 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 {

  @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編碼詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

平定县| 英山县| 蓝山县| 奇台县| 长治县| 石河子市| 吉林市| 永丰县| 巴南区| 贡嘎县| 广河县| 岳池县| 呈贡县| 资溪县| 湖南省| 牟定县| 寿光市| 宁化县| 固原市| 同心县| 临武县| 开原市| 黄平县| 贵定县| 揭阳市| 磴口县| 大新县| 晋江市| 昌宁县| 石楼县| 黄梅县| 四平市| 通城县| 房山区| 四川省| 潜山县| 周至县| 宜章县| 子洲县| 松江区| 岑巩县|