使用JDK的类 BASE64Decoder  BASE64Encoder
 
- package test;  
 
-   
 
- import sun.misc.BASE64Decoder;       
 
- import sun.misc.BASE64Encoder;       
 
-       
 
- public class BASE64       
 
- {       
 
-       
 
-     
 
-     public static byte[] decryptBASE64(String key) throws Exception {                 
 
-         return (new BASE64Decoder()).decodeBuffer(key);                 
 
-     }                 
 
-                     
 
-     
 
-     public static String encryptBASE64(byte[] key) throws Exception {                 
 
-         return (new BASE64Encoder()).encodeBuffer(key);                 
 
-     }         
 
-            
 
-     public static void main(String[] args) throws Exception       
 
-     {       
 
-         String para = "{\"IdList1\": 1,\"IdList2\": [1,2,3,4,5,6,18],\"IdList3\": [1,2]}";  
 
-         String data = BASE64.encryptBASE64(para.getBytes());       
 
-         System.out.println("加密前:"+data);       
 
-                
 
-         byte[] byteArray = BASE64.decryptBASE64(data);       
 
-         System.out.println("解密后:"+new String(byteArray));       
 
-     }       
 
- }      
 
 
 
 
   使用Apache commons codec 类Base64获取【下载地址】  
 
- package test;  
 
-   
 
- import java.io.UnsupportedEncodingException;  
 
-   
 
- import org.apache.commons.codec.binary.Base64;  
 
-   
 
-   
 
-   
 
- public class Base64Util {  
 
-       
 
-     public static String encode(byte[] binaryData) throws UnsupportedEncodingException {  
 
-         return new String(Base64.encodeBase64(binaryData), "UTF-8");  
 
-     }  
 
-       
 
-     public static byte[] decode(String base64String) throws UnsupportedEncodingException {  
 
-         return Base64.decodeBase64(base64String.getBytes("UTF-8"));  
 
-     }  
 
-       
 
-       
 
-     public static void main(String[] args) throws UnsupportedEncodingException {  
 
-         String para = "{\"IdList1\": 1,\"IdList2\": [1,2,3,4,5,6,18],\"IdList3\": [1,2]}";  
 
-         String data = Base64Util.encode(para.getBytes());     
 
-         System.out.println("加密前:"+data);       
 
-                
 
-         byte[] byteArray = Base64Util.decode(data);  
 
-         System.out.println("解密后:"+new String(byteArray));    
 
-     }  
 
-   
 
-   
 
- }  
 
 
 
Java Base64 加密解密
原文:http://www.cnblogs.com/koliop090/p/5203553.html