我们只需要传入一个密码,会直接返回一个加密的密码:
package org.fkit.hrm.util.message;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class CreateMD5 {
public static String getMd5(String plainText) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte[] b = md.digest();
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
int i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
return buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}
简单而且实用