阅读背景:

Java Base64 加密解密

来源:互联网 

应用JDK的类 BASE64Decoder  BASE64Encoder

 

package test;

import sun.misc.BASE64Decoder;     
import sun.misc.BASE64Encoder;     
    
/**   
 * BASE64加密解密   
 */    
public class BASE64     
{     
    
    /**    
     * BASE64解密   
   * @param key          
     * @return          
     * @throws Exception          
     */              
    public static byte[] decryptBASE64(String key) throws Exception {               
        return (new BASE64Decoder()).decodeBuffer(key);               
    }               
                  
    /**         
     * BASE64加密   
   * @param key          
     * @return          
     * @throws Exception          
     */              
    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));     
    }     
}    
package 




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: