package ***;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class BASE64 {
    
    public static void main(String[] args) throws IOException {
        
        String str="123456";
        //编码
        String s=(new BASE64Encoder()).encodeBuffer(str.getBytes()).trim();
        
        
        System.out.println("enbase64 s:"+s);
        //解码
        byte[] bstrs= (new BASE64Decoder()).decodeBuffer(s);
        
        String bstr=new String(bstrs);
        System.out.println("Debase64 bstr:"+bstr.toString());
        
        System.out.println("密文是否相等:"+s.equals(""));
        
        System.out.println("密钥是否相等"+bstr.equals(str));
        
    }
}

 

posted on 2017-02-19 19:06  塞北夜莺  阅读(365)  评论(0编辑  收藏  举报