You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
827 B

package net.micode.notes.tool;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Calc {
/**
* Java中的md5
* @param content 输入的值
* @return 输出md5加密后的值
*/
public static String md5Java(String content) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(content.getBytes());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("NoSuchAlgorithmException", e);
}
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();
}
}