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


package com.czhj.sdk.common.utils;

import com.czhj.sdk.logger.SigmobLog;
import com.umeng.analytics.pro.cb;
import java.io.File;
import java.io.FileInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import kotlin.UByte;

public final class Md5Util {
    private static final String a = "Md5Util";
    private static final int b = 1024;

    private static String a(byte[] bArr) {
        StringBuilder sb = new StringBuilder("");
        if (bArr == null || bArr.length <= 0) {
            return null;
        }
        for (byte b2 : bArr) {
            String hexString = Integer.toHexString(b2 & UByte.MAX_VALUE);
            if (hexString.length() < 2) {
                sb.append(0);
            }
            sb.append(hexString);
        }
        return sb.toString();
    }

    /* JADX WARNING: Removed duplicated region for block: B:35:0x005c A[SYNTHETIC, Splitter:B:35:0x005c] */
    /* JADX WARNING: Removed duplicated region for block: B:40:0x006a A[SYNTHETIC, Splitter:B:40:0x006a] */
    public static String fileMd5(File file) {
        Throwable th;
        FileInputStream fileInputStream;
        MessageDigest messageDigest;
        if (file == null || !file.isFile()) {
            return null;
        }
        byte[] bArr = new byte[2048];
        try {
            messageDigest = MessageDigest.getInstance("md5");
            try {
                fileInputStream = new FileInputStream(file);
                while (true) {
                    try {
                        int read = fileInputStream.read(bArr, 0, 1024);
                        if (read == -1) {
                            break;
                        }
                        messageDigest.update(bArr, 0, read);
                    } catch (Throwable th2) {
                        th = th2;
                        try {
                            SigmobLog.e(th.getMessage());
                            if (messageDigest != null) {
                            }
                            if (fileInputStream != null) {
                            }
                            return null;
                        } catch (Throwable th3) {
                            SigmobLog.e(th3.getMessage());
                        }
                    }
                }
                if (messageDigest != null) {
                    try {
                        messageDigest.clone();
                    } catch (Throwable th4) {
                        SigmobLog.e(th4.getMessage());
                    }
                }
                try {
                    fileInputStream.close();
                } catch (Throwable th5) {
                    SigmobLog.e(th5.getMessage());
                }
                return a(messageDigest.digest());
            } catch (Throwable th6) {
                th = th6;
                fileInputStream = null;
                SigmobLog.e(th.getMessage());
                if (messageDigest != null) {
                }
                if (fileInputStream != null) {
                }
                return null;
            }
        } catch (Throwable th7) {
            th = th7;
            messageDigest = null;
            fileInputStream = null;
            SigmobLog.e(th.getMessage());
            if (messageDigest != null) {
                try {
                    messageDigest.clone();
                } catch (Throwable th8) {
                    SigmobLog.e(th8.getMessage());
                }
            }
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (Throwable th9) {
                    SigmobLog.e(th9.getMessage());
                }
            }
            return null;
        }
        throw th;
        if (fileInputStream != null) {
            fileInputStream.close();
        }
        throw th;
    }

    /* JADX WARNING: Removed duplicated region for block: B:33:0x0061 A[SYNTHETIC, Splitter:B:33:0x0061] */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x006f A[SYNTHETIC, Splitter:B:38:0x006f] */
    public static String fileMd5(String str) {
        Throwable th;
        DigestInputStream digestInputStream;
        FileInputStream fileInputStream;
        if (str == null || !new File(str).exists()) {
            return null;
        }
        try {
            fileInputStream = new FileInputStream(str);
            try {
                digestInputStream = new DigestInputStream(fileInputStream, MessageDigest.getInstance("md5"));
            } catch (Throwable th2) {
                th = th2;
                digestInputStream = null;
                try {
                    SigmobLog.e(th.getMessage());
                    if (fileInputStream != null) {
                    }
                    if (digestInputStream != null) {
                    }
                    return null;
                } catch (Throwable th3) {
                    SigmobLog.e(th3.getMessage());
                }
            }
            try {
                while (digestInputStream.read(new byte[1024]) > 0) {
                }
                String a2 = a(digestInputStream.getMessageDigest().digest());
                try {
                    fileInputStream.close();
                } catch (Throwable th4) {
                    SigmobLog.e(th4.getMessage());
                }
                try {
                    digestInputStream.close();
                } catch (Throwable th5) {
                    SigmobLog.e(th5.getMessage());
                }
                return a2;
            } catch (Throwable th6) {
                th = th6;
                SigmobLog.e(th.getMessage());
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (Throwable th7) {
                        SigmobLog.e(th7.getMessage());
                    }
                }
                if (digestInputStream != null) {
                    try {
                        digestInputStream.close();
                    } catch (Throwable th8) {
                        SigmobLog.e(th8.getMessage());
                    }
                }
                return null;
            }
        } catch (Throwable th9) {
            th = th9;
            fileInputStream = null;
            digestInputStream = null;
            SigmobLog.e(th.getMessage());
            if (fileInputStream != null) {
            }
            if (digestInputStream != null) {
            }
            return null;
        }
        throw th;
        if (digestInputStream != null) {
            digestInputStream.close();
        }
        throw th;
    }

    public static String md5(String str) {
        if (str == null) {
            return null;
        }
        char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] bytes = str.getBytes("UTF-8");
            MessageDigest instance = MessageDigest.getInstance("md5");
            instance.update(bytes);
            byte[] digest = instance.digest();
            char[] cArr2 = new char[(digest.length * 2)];
            int i = 0;
            for (byte b2 : digest) {
                int i2 = i + 1;
                cArr2[i] = cArr[(b2 >>> 4) & 15];
                i = i2 + 1;
                cArr2[i2] = cArr[b2 & cb.m];
            }
            return new String(cArr2);
        } catch (Throwable th) {
            SigmobLog.e(th.getMessage());
            return null;
        }
    }
}