public class MD5Utils {
/**
* 加密
* @param context
*/
public static String encrypByMd5(String context) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
// update处理
md.update(context.getBytes());
// 调用该方法完成计算
byte [] encryContext = md.digest();
int i;
StringBuilder buf = new StringBuilder("");
//做相应的转化(十六进制)
for (byte b : encryContext) {
i = b;
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;
}
}
}
11-24
427
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-20
4178
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-22
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交