`

base64加密解密

阅读更多
  1. package test;  
  2.   
  3. import sun.misc.BASE64Decoder;  
  4. import sun.misc.BASE64Encoder;  
  5.       
  6. /**    
  7.  * BASE64加密解密    
  8.  */      
  9. public class BASE64       
  10. {       
  11.     /**     
  12.      * BASE64解密    
  13.      * @param key           
  14.      * @return           
  15.      * @throws Exception           
  16.      */                
  17.     public static byte[] decryptBASE64(String key) throws Exception {                 
  18.         return (new BASE64Decoder()).decodeBuffer(key);                 
  19.     }                                   
  20.     /**          
  21.      * BASE64加密    
  22.      * @param key           
  23.      * @return           
  24.      * @throws Exception           
  25.      */                
  26.     public static String encryptBASE64(byte[] key) throws Exception {                 
  27.         return (new BASE64Encoder()).encodeBuffer(key);                 
  28.     }         
  29.       
  30.     /*测试*/  
  31.     public static void main(String[] args) throws Exception       
  32.     {       
  33.         String data = BASE64.encryptBASE64("".getBytes());       
  34.         System.out.println("解密前:"+data);       
  35.                
  36.         byte[] byteArray = BASE64.decryptBASE64(data);       
  37.         System.out.println("解密后:"+new String(byteArray));       
  38.     }       
  39. }   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics