首页>代码>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日
最近浏览更多
WBelong  LV7 3月29日
NC26ZX 2月15日
暂无贡献等级
1195146710  LV4 1月16日
asddwh  LV12 2023年12月26日
qq22183138 2023年11月2日
暂无贡献等级
morelian 2023年10月20日
暂无贡献等级
微信网友_6691482819710976 2023年10月14日
暂无贡献等级
世间哪有真情在 2023年10月14日
暂无贡献等级
weilaizhisheng  LV21 2023年9月28日
903201717 2023年9月12日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友