TNT blog  
日历
<2025年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
统计
  • 随笔 - 5
  • 文章 - 40
  • 评论 - 7
  • 引用 - 0

导航

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

home

搜索

  •  

最新随笔

最新评论

阅读排行榜

 
/**
    * Encode a string using Base64 encoding. Used when storing passwords
    * as cookies.
    *
    * This is weak encoding in that anyone can use the decodeString
    * routine to reverse the encoding.
    *
    * @param str
    * @return String
    */
   public static String encodeString(String str)  {
       sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
       return encoder.encodeBuffer(str.getBytes()).trim();
   }

   /**
    * Decode a string using Base64 encoding.
    *
    * @param str
    * @return String
    */
   public static String decodeString(String str) {
       sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
       try {
           return new String(dec.decodeBuffer(str));
       } catch (IOException io) {
               throw new RuntimeException(io.getMessage(), io.getCause());
       }
    }

posted on 2006-06-01 10:40 TNT 阅读(201) 评论(0)  编辑  收藏 所属分类: JAVA
 
Copyright © TNT Powered by: 博客园 模板提供:沪江博客