import java.security.*;public class MD5Encode {
public static String encode(String str) {
String res = null;
try {
res = new String(str);
MessageDigest md = MessageDigest.getInstance("MD5");
res = byte2hexString(md.digest(res.getBytes()));
} catch (Exception ex) {
}
return res;
} public static final String byte2hexString(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if (((int) bytes[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString((int) bytes[i] & 0xff, 16));
}
return buf.toString();
}
}