隨筆-22  評論-6  文章-17  trackbacks-0

          一個利用byte2hexString的簡單MD5的應用,把你的密碼加密

          				import java.security.MessageDigest;

          public static String MD5Encode(String sourceString) {?
          ?? String resultString = null;?
          ?? try{?
          ????? resultString=new String(sourceString);?
          ????? MessageDigest md = MessageDigest.getInstance("MD5");?
          ????? resultString=byte2hexString(md.digest(resultString.getBytes()));?
          ?? }catch (Exception ex) {?
          ?? }?
          ?? return resultString;?
          }?
          ?
          public staticfinal String byte2hexString(byte[] bytes) {
          ?? StringBuffer buf = new StringBuffer(bytes.length * 2);
          ?? for (int i = 0; i < bytes.length; i++) {
          ????? if ( ((int) bytes[i] & 0xff) < 0x10) {
          ??????? buf.append("0");
          ???? }
          ????? buf.append(Long.toString((int) bytes[i] & 0xff, 16));
          ?? }
          ?? return buf.toString();
          }

          public staticvoid main(String[] args) throws Exception {
          ?? System.out.println(MD5Encode("abc"));?
          ?? System.out.println(MD5Encode("hello"));?
          ?? System.out.println(MD5Encode("123456"));?
          ?? System.out.println(MD5Encode("你好Blog"));
          }

          結果:

          900150983cd24fb0d6963f7d28e17f72
          5d41402abc4b2a76b9719d911017c592
          e10adc3949ba59abbe56e057f20f883e
          2fc0228c7266d61d184dcf2a6b3b81d3
          posted on 2006-04-27 11:47 surffish 閱讀(263) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 子洲县| 弋阳县| 慈利县| 禄劝| 钦州市| 那坡县| 栾川县| 商河县| 商洛市| 江城| 伊金霍洛旗| 彩票| 北海市| 山阳县| 洪泽县| 凉城县| 科尔| 青海省| 商南县| 赫章县| 剑阁县| 湖南省| 北宁市| 镇巴县| 云霄县| 潞城市| 井研县| 崇礼县| 礼泉县| 商水县| 伊吾县| 闵行区| 新竹市| 克山县| 麻栗坡县| 宁远县| 那坡县| 延安市| 高平市| 综艺| 基隆市|