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];  
    }  
    
 
    
}
 最近下载更多
最近下载更多
                
                15719908287     LV10
                2024年5月30日
            
            
        
                sdfddd     LV4
                2024年5月16日
            
            
        
                FF加菲猫     LV4
                2024年2月13日
            
            
        
                liuchang183     LV5
                2023年12月12日
            
            
        
                dj931127     LV4
                2023年11月22日
            
            
        
                ewan007     LV30
                2023年4月7日
            
            
        
                neuifgvf     LV2
                2023年3月19日
            
            
        
                SecretLj     LV3
                2023年2月27日
            
            
        
                忧麦紫     LV18
                2023年2月24日
            
            
        
                ningningnn     LV3
                2023年2月23日
            
            
         最近浏览更多
最近浏览更多
                
                奋斗的小蚂蚁     LV16
                10月17日
            
            
        
                ytxyyay    
                5月21日
            
            
                    暂无贡献等级
            
        
                ClintClint      LV1
                3月31日
            
            
        
                ryadmin123     LV2
                2月7日
            
            
        
                kiel22     LV2
                2024年12月25日
            
            
        
                郭宇航裹裹     LV5
                2024年12月24日
            
            
        
                571818771     LV3
                2024年12月17日
            
            
        
                微信网友_7293659494813696    
                2024年12月12日
            
            
                    暂无贡献等级
            
        
                krispeng     LV15
                2024年9月6日
            
            
        
                848732002    
                2024年8月27日
            
            
                    暂无贡献等级
            
        
 
                 
                 
                