本文实例为大家分享了java使用Base64编码的具体代码,供大家参考,具体内容如下
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)