首页>代码>java学生会管理信息系统,活动发布,报名等>/学生会/CommodityMIS/src/edu/gdut/imis/commodity/util/MD5Utils.java
package edu.gdut.imis.commodity.util;

import java.security.MessageDigest;

public class MD5Utils {

    private final static String[] hexDigits = {"0", "1", "2", "3", "4",  
        "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};  
      
    public static String generatePassword(String inputString){  
        return encodeByMD5(inputString);  
    }  
     
    public static boolean validatePassword(String password, String inputString){  
        if(password.equals(encodeByMD5(inputString))){  
            return true;  
        } else{  
            return false;  
        }  
    }  
    private static String encodeByMD5(String originString){  
        if (originString != null){  
            try{  
                MessageDigest md = MessageDigest.getInstance("MD5");  
                byte[] results = md.digest(originString.getBytes());  
                String resultString = byteArrayToHexString(results);  
                return resultString.toUpperCase();  
            } catch(Exception ex){  
                ex.printStackTrace();  
            }  
        }  
        return null;  
    }  
    
    private static String byteArrayToHexString(byte[] b){  
        StringBuffer resultSb = new StringBuffer();  
        for (int i = 0; i < b.length; i++){  
            resultSb.append(byteToHexString(b[i]));  
        }  
        return resultSb.toString();  
    }  
      
    private static String byteToHexString(byte b){  
        int n = b;  
        if (n < 0)  
            n = 256 + n;  
        int d1 = n / 16;  
        int d2 = n % 16;  
        return hexDigits[d1] + hexDigits[d2];  
    }  
    
 
    
}
最近下载更多
世间哪有真情在 2023年10月14日
暂无贡献等级
841146628  LV4 2023年6月12日
tomhuang  LV1 2023年3月31日
763602934  LV2 2023年3月8日
不足挂齿  LV2 2023年2月1日
poipoiiop  LV8 2023年1月3日
2517786374  LV4 2022年11月28日
小丶无奈  LV10 2022年6月16日
17683946472  LV9 2022年5月14日
309681  LV5 2022年5月11日
最近浏览更多
zq1685  LV4 6月14日
shuaiqi 4月22日
暂无贡献等级
陈小灏  LV18 1月4日
krispeng  LV15 2024年9月22日
TY0165  LV20 2024年6月22日
sunlea  LV20 2024年5月12日
1941549176  LV4 2024年4月29日
WBelong  LV8 2024年3月29日
NC26ZX 2024年2月15日
暂无贡献等级
1195146710  LV4 2024年1月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友