夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          package com.roadway.website.util;

          import java.security.MessageDigest;

          /**
           * @discription:A tool of Secutity by SHA
           * 
          @author     :Hui Wanpeng
           * @time       :2008-1-25
           * 
          @version    :1.0
           * 
          @see        :no
           
          */

          public class Security {
              
          private synchronized static byte[] encode(String origin) {
                  
          byte[] hash = null;
                  
          try {
                      MessageDigest md 
          = MessageDigest.getInstance("MD5");
                      md.reset();
                      hash 
          = md.digest(origin.getBytes());
                  }
           catch (Exception ex) {
                      ex.printStackTrace();
                  }

                  
          return hash;
              }


              
          public synchronized static String getPassword(String origin) {
                  String result 
          = "";
                  
          byte[] hash = Security.encode(origin);
                  
          for (int i = 0; i < hash.length; i++{
                      
          int itemp = hash[i]&0xFF;
                      
          if(itemp<16) result += "0";
                      result 
          += Integer.toString(itemp, 16).toUpperCase();
                  }

                  
          return result;
              }


              
          public synchronized static boolean isPassword(String origin, String result) {
                  
          if (Security.getPassword(origin).equals(result)) {
                      
          return true;
                  }

                  
          return false;
              }

              
          public static void main(String[] args){
                  String result 
          = "";
                  result 
          = Security.getPassword("huiwanpeng");
                  System.out.println(result);
              }

          }
          posted on 2008-01-25 14:59 HUIKK 閱讀(730) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 宿州市| 江北区| 鸡泽县| 奉节县| 中方县| 库车县| 肥城市| 彭山县| 崇明县| 年辖:市辖区| 诸城市| 青州市| 新安县| 仲巴县| 昌宁县| 湟中县| 台湾省| 城口县| 祁门县| 固阳县| 改则县| 彝良县| 江川县| 天长市| 峨边| 正宁县| 湘潭市| 大名县| 天门市| 图片| 东阳市| 水城县| 民和| 日照市| 宁陕县| 普洱| 顺义区| 微博| 沈阳市| 十堰市| 谷城县|