package com.qq.e.comm.util; import android.util.Base64; import androidx.core.view.InputDeviceCompat; import com.mbridge.msdk.foundation.same.report.e; import com.sigmob.sdk.base.mta.PointType; import java.io.File; import java.io.FileInputStream; import java.security.MessageDigest; public class Md5Util { private static final String[] a = {"0", "1", "2", "3", "4", "5", "6", "7", "8", PointType.SIGMOB_ERROR, "a", "b", "c", "d", e.a, "f"}; /* JADX DEBUG: Failed to insert an additional move for type inference into block B:11:0x000f */ /* JADX DEBUG: Multi-variable search result rejected for r6v0, resolved type: byte[] */ /* JADX DEBUG: Multi-variable search result rejected for r2v1, resolved type: byte */ /* JADX DEBUG: Multi-variable search result rejected for r2v2, resolved type: int */ /* JADX DEBUG: Multi-variable search result rejected for r2v6, resolved type: int */ /* JADX WARN: Multi-variable type inference failed */ public static String byteArrayToHexString(byte[] bArr) { StringBuffer stringBuffer = new StringBuffer(); for (byte b : bArr) { if (b < 0) { b += 256; } int i = (b == true ? 1 : 0) / 16; StringBuilder sb = new StringBuilder(); String[] strArr = a; sb.append(strArr[i]); sb.append(strArr[b % 16]); stringBuffer.append(sb.toString()); } return stringBuffer.toString(); } /* JADX WARNING: Removed duplicated region for block: B:24:0x003a A[SYNTHETIC, Splitter:B:24:0x003a] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x0041 A[SYNTHETIC, Splitter:B:30:0x0041] */ public static String encode(File file) { Throwable th; MessageDigest instance; FileInputStream fileInputStream; if (file != null && file.exists()) { FileInputStream fileInputStream2 = null; try { instance = MessageDigest.getInstance("MD5"); fileInputStream = new FileInputStream(file); } catch (Exception unused) { if (fileInputStream2 != null) { try { fileInputStream2.close(); } catch (Exception unused2) { } } return ""; } catch (Throwable th2) { th = th2; if (fileInputStream2 != null) { try { fileInputStream2.close(); } catch (Exception unused3) { } } throw th; } try { byte[] bArr = new byte[16384]; while (true) { int read = fileInputStream.read(bArr); if (read <= 0) { break; } instance.update(bArr, 0, read); } String byteArrayToHexString = byteArrayToHexString(instance.digest()); try { fileInputStream.close(); } catch (Exception unused4) { } return byteArrayToHexString; } catch (Exception unused5) { fileInputStream2 = fileInputStream; if (fileInputStream2 != null) { } return ""; } catch (Throwable th3) { th = th3; fileInputStream2 = fileInputStream; if (fileInputStream2 != null) { } throw th; } } return ""; } public static String encode(String str) { try { String str2 = new String(str); try { return byteArrayToHexString(MessageDigest.getInstance("MD5").digest(str2.getBytes("UTF-8"))); } catch (Exception unused) { return str2; } } catch (Exception unused2) { return null; } } public static String encodeBase64String(String str) { try { return byteArrayToHexString(MessageDigest.getInstance("MD5").digest(Base64.decode(str, 0))); } catch (Exception unused) { GDTLogger.d("Exception while md5 base64String"); return null; } } public static byte[] hexStringtoByteArray(String str) { if (str.length() % 2 != 0) { return null; } byte[] bArr = new byte[(str.length() / 2)]; for (int i = 0; i < str.length() - 1; i += 2) { char charAt = str.charAt(i); char charAt2 = str.charAt(i + 1); char lowerCase = Character.toLowerCase(charAt); char lowerCase2 = Character.toLowerCase(charAt2); int i2 = ((lowerCase <= '9' ? lowerCase - '0' : (lowerCase - 'a') + 10) << 4) + (lowerCase2 <= '9' ? lowerCase2 - '0' : (lowerCase2 - 'a') + 10); if (i2 > 127) { i2 += InputDeviceCompat.SOURCE_ANY; } bArr[i / 2] = (byte) i2; } return bArr; } }