/**
* @author hcy
* @version 1.0
* @date 2020/3/1 下午6:37
*/
public class Test2 {
//待加密的密码
public static String password = "123456";

public static void main(String args[]) {
//结果字符串
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(password.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
System.out.println("MD5(" + password + ",32小写) = " + result);
System.out.println("MD5(" + password + ",32大写) = " + result.toUpperCase());
System.out.println("++++++++++++++++++++++++ 看结果咯 +++++++++++++++++++++++");
System.out.println("MD5(" + password + ",16小写) = " + buf.toString().substring(8, 24));
System.out.println("MD5(" + password + ",16大写) = " + buf.toString().substring(8, 24).toUpperCase());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
Connected to the target VM, address: '127.0.0.1:36603', transport: 'socket'
MD5(123456,32小写) = e10adc3949ba59abbe56e057f20f883e
MD5(123456,32大写) = E10ADC3949BA59ABBE56E057F20F883E
++++++++++++++++++++++++ 看结果咯 +++++++++++++++++++++++
MD5(123456,16小写) = 49ba59abbe56e057
MD5(123456,16大写) = 49BA59ABBE56E057