xuxiuxi
2017-08-11 5f12988a77d078a5e5155c9a301e45bfd288d7e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package cn.com.basic.face.util;
 
import java.security.MessageDigest;
 
public class MD5Encoder {
 
    public static String encode(String string) throws Exception {
        byte[] hash = MessageDigest.getInstance("MD5").digest(
                string.getBytes("UTF-8"));
        StringBuilder hex = new StringBuilder(hash.length * 2);
        for (byte b : hash) {
            if ((b & 0xFF) < 0x10) {
                hex.append("0");
            }
            hex.append(Integer.toHexString(b & 0xFF));
        }
        return hex.toString();
    }
}