java base64加密算法

来源:互联网 发布:如何输入淘宝口令 编辑:程序博客网 时间:2024/06/05 20:55
  1. import sun.misc.BASE64Decoder;     
  2. import sun.misc.BASE64Encoder;     
  3.     
  4. /**   
  5.  * BASE64加密解密   
  6.  */    
  7. public class BASE64     
  8. {     
  9.     
  10.     /**    
  11.      * BASE64解密   
  12.    * @param key          
  13.      * @return          
  14.      * @throws Exception          
  15.      */              
  16.     public static byte[] decryptBASE64(String key) throws Exception {               
  17.         return (new BASE64Decoder()).decodeBuffer(key);               
  18.     }               
  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.     public static void main(String[] args) throws Exception     
  31.     {     
  32.         String data = BASE64.encryptBASE64("http://aub.iteye.com/".getBytes());     
  33.         System.out.println("加密后:"+data);     
  34.              
  35.         byte[] byteArray = BASE64.decryptBASE64(data);     
  36.         System.out.println("解密后:"+new String(byteArray));     
  37.     }     
  38. }    
  39.    
0 0
原创粉丝点击