public static String MD5(String sourceStr) {
if (TextUtils.isEmpty(sourceStr)) {
return "";
}
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(sourceStr.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (byte value : b) {
i = value;
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
result = buf.toString();
} catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
return result;
}
Android之字符串转为MD5
Java实现MD5字符串加密算法的示例
最新推荐文章于 2024-03-01 12:05:36 发布
本文介绍了如何在Java中使用MD5算法对输入字符串进行加密,包括空字符串处理、MessageDigest类的实例化和加密过程的详细步骤。
422

被折叠的 条评论
为什么被折叠?



