import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MessageDigestTest {
public static String MD5(String toEncrypt) {
StringBuffer toReturn = new StringBuffer();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(toEncrypt.getBytes());
byte[] toChapterDigest = md.digest();
for (byte b : toChapterDigest) {
toReturn.append(String.format("%02x", b));
}
} catch (NoSuchAlgorithmException e) {
// ignore
}
return toReturn.toString();
}
}
Java MD5加密方法
最新推荐文章于 2024-06-24 07:45:00 发布