Java MD5 加密类
import java.security.MessageDigest;
public class MD5 {
public MD5() {
}
private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
public static String MD5Encode(String code) {
String NewCode = null;
try {
NewCode = new String(code);
MessageDigest MD = MessageDigest.getInstance("MD5");
NewCode = byteArrayToHexString(MD.digest(NewCode.getBytes()));
} catch (Exception exception) {
}
return NewCode;
}
public static String byteArrayToHexString(byte bts[]) {
StringBuffer str = new StringBuffer();
for (int i = 0; i < bts.length; i++)
str.append(byteToHexString(bts[i]));
return str.toString();
}
private static String byteToHexString(byte bt) {
int Num = bt;
if (Num < 0)
Num += 256;
int Int = Num / 16;
int ox = Num % 16;
return hexDigits[Int] + hexDigits[ox];
}
}