You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							70 lines
						
					
					
						
							2.4 KiB
						
					
					
				
			
		
		
	
	
							70 lines
						
					
					
						
							2.4 KiB
						
					
					
				| //package com.ynxbd.wx.utils;
 | |
| //
 | |
| //
 | |
| //import org.apache.commons.lang3.StringUtils;
 | |
| //
 | |
| //import java.security.MessageDigest;
 | |
| //import java.security.NoSuchAlgorithmException;
 | |
| //
 | |
| //public class MD5Util {
 | |
| //
 | |
| //    private static String byteArrayToHexString(byte[] b) {
 | |
| //        StringBuilder sb = new StringBuilder();
 | |
| //        for (byte value : b) sb.append(byteToHexString(value));
 | |
| //
 | |
| //        return sb.toString();
 | |
| //    }
 | |
| //
 | |
| //    private static String byteToHexString(byte b) {
 | |
| //        int n = b;
 | |
| //        if (n < 0)
 | |
| //            n += 256;
 | |
| //        int d1 = n / 16;
 | |
| //        int d2 = n % 16;
 | |
| //        return hexDigits[d1] + hexDigits[d2];
 | |
| //    }
 | |
| //
 | |
| //    public static String MD5Encode(String origin, String charsetName) {
 | |
| //        String resultString = null;
 | |
| //        try {
 | |
| //            resultString = origin;
 | |
| //            MessageDigest md = MessageDigest.getInstance("MD5");
 | |
| //            if (StringUtils.isEmpty(charsetName)) {
 | |
| //                resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
 | |
| //            } else {
 | |
| //                resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetName)));
 | |
| //            }
 | |
| //        } catch (Exception e) {
 | |
| //            e.printStackTrace();
 | |
| //        }
 | |
| //        return resultString;
 | |
| //    }
 | |
| //
 | |
| //    private static final String[] hexDigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
 | |
| //
 | |
| //    public static String MD5(String sourceStr) {
 | |
| //        String result = "";
 | |
| //        try {
 | |
| //            MessageDigest md = MessageDigest.getInstance("MD5");
 | |
| //            md.update(sourceStr.getBytes());
 | |
| //            byte[] b = md.digest();
 | |
| //            int i;
 | |
| //            StringBuilder sb = new StringBuilder("");
 | |
| //            for (byte value : b) {
 | |
| //                i = value;
 | |
| //                if (i < 0)
 | |
| //                    i += 256;
 | |
| //                if (i < 16)
 | |
| //                    sb.append("0");
 | |
| //                sb.append(Integer.toHexString(i));
 | |
| //            }
 | |
| //            result = sb.toString();
 | |
| //            System.out.println("MD5(" + sourceStr + ",32) = " + result);
 | |
| //            System.out.println("MD5(" + sourceStr + ",16) = " + sb.substring(8, 24));
 | |
| //        } catch (NoSuchAlgorithmException e) {
 | |
| //            e.printStackTrace();
 | |
| //        }
 | |
| //        return result;
 | |
| //    }
 | |
| //
 | |
| //}
 | |
| 
 |