package cn.buk.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created by yfdai on 2015-1-12.
*/
public class EncryptUtil {
// MD5加密
public static String MD5Encoding(String source)
throws NoSuchAlgorithmException {
MessageDigest mdInst = MessageDigest.getInstance("MD5");
byte[] input = source.getBytes();
mdInst.update(input);
byte[] output = mdInst.digest();
int i = 0;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < output.length; offset++) {
i = output[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
return buf.toString();
}
}