一、示例

CommonUtil.java

package com.ray.test.des;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
 
public class CommonUtil {
    public static void main(String[] args) {
      
       byte[] before=new byte[] {80, 75, 3, 4, 10, 60, 82, -83, 68, 8, 0, 28, 0, 80, 97, 121, 108, 108};
       String mes=getStringFromBytes(before);
    
       byte[] after=getBytesFromString(  mes);
       
       
       System.out.println("before= "+Arrays.toString(before));
       System.out.println("after = "+Arrays.toString(after));
    }
    
    
    public static String  getStringFromBytes( byte[] before ) {
          BASE64Encoder enc=new BASE64Encoder();
          String mes=enc.encodeBuffer(before); //使用BASE64编码
        return mes;
    }
    
    public static byte[]  getBytesFromString( String mes) {
         BASE64Decoder dec=new BASE64Decoder();
         byte[]after=null;
         try {
             after =dec.decodeBuffer(mes);//使用BASE64解码
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }       return after;
  }
  
    
    
}
View Code

相关文章:

  • 2022-03-05
  • 2021-07-26
  • 2022-03-09
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-07-19
  • 2022-01-11
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-12-27
  • 2021-08-11
相关资源
相似解决方案