翰林优商.apk(点击下载) / ac.java


package com.kwad.sdk.utils;

import com.kwad.sdk.crash.utils.b;
import java.io.File;
import java.io.FileInputStream;
import java.security.MessageDigest;
import kotlin.UByte;

public final class ac {
    static final char[] HEX_CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static String ag(File file) {
        Throwable th;
        Exception e;
        FileInputStream fileInputStream;
        FileInputStream fileInputStream2 = null;
        if (file == null) {
            return null;
        }
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            fileInputStream = new FileInputStream(file);
            try {
                byte[] bArr = new byte[4096];
                while (true) {
                    int read = fileInputStream.read(bArr);
                    if (read != -1) {
                        instance.update(bArr, 0, read);
                    } else {
                        String v = v(instance.digest());
                        b.closeQuietly(fileInputStream);
                        return v;
                    }
                }
            } catch (Exception e2) {
                e = e2;
                try {
                    com.kwad.sdk.core.e.b.printStackTraceOnly(e);
                    b.closeQuietly(fileInputStream);
                    return null;
                } catch (Throwable th2) {
                    th = th2;
                    fileInputStream2 = fileInputStream;
                    b.closeQuietly(fileInputStream2);
                    throw th;
                }
            }
        } catch (Exception e3) {
            e = e3;
            fileInputStream = null;
            com.kwad.sdk.core.e.b.printStackTraceOnly(e);
            b.closeQuietly(fileInputStream);
            return null;
        } catch (Throwable th3) {
            th = th3;
            b.closeQuietly(fileInputStream2);
            throw th;
        }
    }

    public static String fo(String str) {
        return u(str.getBytes());
    }

    public static String fp(String str) {
        try {
            MessageDigest instance = MessageDigest.getInstance("SHA-1");
            instance.update(str.getBytes());
            byte[] digest = instance.digest();
            return toHexString(digest, 0, digest.length);
        } catch (Exception e) {
            com.kwad.sdk.core.e.b.printStackTrace(e);
            return "";
        }
    }

    public static String toHexString(byte[] bArr, int i, int i2) {
        an.checkNotNull(bArr);
        if (i2 + 0 <= bArr.length) {
            int i3 = i2 * 2;
            char[] cArr = new char[i3];
            int i4 = 0;
            for (int i5 = 0; i5 < i2; i5++) {
                int i6 = bArr[i5 + 0] & UByte.MAX_VALUE;
                int i7 = i4 + 1;
                char[] cArr2 = HEX_CHARS;
                cArr[i4] = cArr2[i6 >> 4];
                i4 = i7 + 1;
                cArr[i7] = cArr2[i6 & 15];
            }
            return new String(cArr, 0, i3);
        }
        throw new IndexOutOfBoundsException();
    }

    public static String u(byte[] bArr) {
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.update(bArr);
            byte[] digest = instance.digest();
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                int i = b;
                if (b < 0) {
                    i = b + 256;
                }
                if (i < 16) {
                    sb.append("0");
                }
                sb.append(Integer.toHexString(i == 1 ? 1 : 0));
            }
            return sb.toString();
        } catch (Exception unused) {
            return "";
        }
    }

    private static String v(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        int length = bArr.length;
        for (int i = 0; i < length; i++) {
            stringBuffer.append(String.format("%02x", Byte.valueOf(bArr[i])));
        }
        return stringBuffer.toString();
    }
}