48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package com.ubt.jimu.utils;
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class Md5Utils {
|
|
public static String a(String str) {
|
|
if (android.text.TextUtils.isEmpty(str)) {
|
|
return "";
|
|
}
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
|
messageDigest.update(str.getBytes());
|
|
return a(messageDigest.digest());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return "";
|
|
}
|
|
}
|
|
|
|
private static String a(byte[] bArr) {
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
for (byte b : bArr) {
|
|
String hexString = Integer.toHexString(b & 255);
|
|
if (hexString.length() == 1) {
|
|
stringBuffer.append('0');
|
|
}
|
|
stringBuffer.append(hexString);
|
|
}
|
|
return stringBuffer.toString();
|
|
}
|
|
|
|
public static String a(String str, int i) {
|
|
if (android.text.TextUtils.isEmpty(str)) {
|
|
return "";
|
|
}
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
|
messageDigest.update(str.getBytes());
|
|
String a = a(messageDigest.digest());
|
|
return android.text.TextUtils.isEmpty(a) ? "" : a.length() <= i ? a : a.substring(a.length() - i, a.length());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return "";
|
|
}
|
|
}
|
|
}
|