allen
          專注于java ee技術,包括struts,jsf,webwork,spring,hibernate,ibatis
          posts - 7,  comments - 9,  trackbacks - 0
          MD5

          import java.security.*;


          public class MD5
          {
          ? private static MD5 md5 = null;
          ? private MD5(){}
          ? public static MD5 getInstance()
          ? {
          ??? if (md5 == null)
          ??? {
          ????? md5 = new MD5();
          ??? }
          ??? return md5;
          ? }

          ? /**
          ?? * Description:encrypt the String by "MD5"
          ?? * @param str String
          ?? * @return String
          ?? */
          ? public String calcMD5(String str)
          ? {
          ??? try
          ??? {
          ????? MessageDigest alga = MessageDigest.getInstance("MD5");
          ????? alga.update(str.getBytes());
          ????? byte[] digesta = alga.digest();
          ????? return byte2hex(digesta);
          ??? }
          ??? catch (Exception e)
          ??? {
          ????? //System.out.println(e.getMessage());
          ????? return null;
          ??? }
          ? }

          ? private String byte2hex(byte[] b)
          ? {
          ??? String hs = "";
          ??? String stmp = "";
          ??? for (int n = 0; n < b.length; n++)
          ??? {
          ????? stmp = (Integer.toHexString(b[n] & 0XFF));
          ????? if (stmp.length() == 1)
          ????? {
          ??????? hs = hs + "0" + stmp;
          ????? }
          ????? else
          ????? {
          ??????? hs = hs + stmp;
          ????? }
          ????? if (n < b.length - 1)
          ????? {
          ??????? hs = hs + "";
          ????? }
          ??? }
          ??? return hs;
          ? }
          }

          posted on 2006-12-08 13:49 robbin163 閱讀(365) 評論(1)  編輯  收藏

          FeedBack:
          # re: MD5
          2007-08-30 11:25 | dreamstone
          不錯  回復  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 潼关县| 曲靖市| 阿拉尔市| 武威市| 克拉玛依市| 尉犁县| 合川市| 中阳县| 甘德县| 正阳县| 莱州市| 海伦市| 蓬安县| 康保县| 台中县| 余庆县| 农安县| 河北区| 阿坝县| 彰化县| 黄龙县| 商城县| 宁德市| 白玉县| 和顺县| 湾仔区| 长兴县| 土默特左旗| 任丘市| 冷水江市| 新闻| 随州市| 巴里| 平南县| 吉林市| 东乌珠穆沁旗| 梅州市| 雅江县| 商南县| 华蓥市| 碌曲县|