package com.example.testdemo.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Utils {
//创建MD5加密方法md5
public static String md5(String text){
MessageDigest digest=null;
try {
digest = MessageDigest.getInstance("md5");
byte[] result = digest.digest(text.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : result) {
int number = b & 0xff;
String hex = Integer.toHexString(number);
if (hex.length() == 1) {
sb.append("0" + hex);
} else {
sb.append(hex);
}
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
从第十二行开始都是什么意思啊?byte[] result = digest.digest(text.getBytes());
为什么用了两次digest。下面的for语句又是什么意思啊?详解必采纳