package com.nd.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];  
    }  
    
 
    
}
最近下载更多
FF加菲猫  LV4 2月13日
liuchang183  LV5 2023年12月12日
dj931127  LV4 2023年11月22日
ewan007  LV29 2023年4月7日
neuifgvf  LV2 2023年3月19日
SecretLj  LV3 2023年2月27日
忧麦紫  LV18 2023年2月24日
ningningnn  LV3 2023年2月23日
北方菜  LV11 2023年2月9日
1755754535  LV5 2022年12月27日
最近浏览更多
yimrrrrr 4月17日
暂无贡献等级
silences_ftjh  LV10 3月22日
gggg1111 3月16日
暂无贡献等级
FF加菲猫  LV4 2月13日
颜菜菜  LV2 2023年12月19日
liuchang183  LV5 2023年12月12日
WBelong  LV7 2023年12月11日
mukoooo  LV2 2023年12月5日
2951024  LV1 2023年11月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友