java Base 64符号化の例を使用する


本論文の例では、JavaはBase 64符号化の具体的なコードを使って共有しています。
Test Base 64

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")));
  }
 }
Base 64工具類

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です。Base 64コードを使って详しく整理して、皆さんに助けてほしいです。もし何か疑问があれば、メッセージをください。小编はすぐに皆さんに返事します。ここでも私たちのサイトを応援してくれてありがとうございます。