allen
          專注于java ee技術(shù),包括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 閱讀(363) 評論(1)  編輯  收藏

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

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


          網(wǎng)站導(dǎo)航:
           

          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乌兰县| 道孚县| 广饶县| 安顺市| 西峡县| 博湖县| 左贡县| 讷河市| 鄢陵县| 会同县| 略阳县| 延长县| 和硕县| 景德镇市| 噶尔县| 嘉峪关市| 元朗区| 汉沽区| 积石山| 康马县| 永川市| 平阳县| 新竹市| 冕宁县| 德惠市| 高陵县| 宿松县| 莎车县| 江都市| 丁青县| 江山市| 花垣县| 镇巴县| 东港市| 彭泽县| 建始县| 秀山| 扎兰屯市| 陆河县| 沾化县| 宜良县|