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算法对输入字符串进行加密,包括空字符串处理、MessageDigest类的实例化和加密过程的详细步骤。
摘要由CSDN通过智能技术生成