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


package zj.xuitls.common.util;

import com.umeng.analytics.pro.cb;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

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

    private MD5() {
    }

    public static String toHexString(byte[] bArr) {
        if (bArr == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder(bArr.length * 2);
        for (byte b : bArr) {
            char[] cArr = hexDigits;
            sb.append(cArr[(b >> 4) & 15]);
            sb.append(cArr[b & cb.m]);
        }
        return sb.toString();
    }

    /* JADX DEBUG: Multi-variable search result rejected for r2v1, resolved type: java.io.FileInputStream */
    /* JADX WARN: Multi-variable type inference failed */
    public static String md5(File file) throws IOException {
        Throwable th;
        FileChannel fileChannel;
        NoSuchAlgorithmException e;
        FileChannel fileChannel2 = null;
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                fileChannel2 = fileInputStream.getChannel();
                instance.update(fileChannel2.map(FileChannel.MapMode.READ_ONLY, 0, file.length()));
                byte[] digest = instance.digest();
                IOUtil.closeQuietly(fileInputStream);
                IOUtil.closeQuietly(fileChannel2);
                return toHexString(digest);
            } catch (NoSuchAlgorithmException e2) {
                e = e2;
                fileChannel = fileChannel2;
                fileChannel2 = fileInputStream;
                try {
                    throw new RuntimeException(e);
                } catch (Throwable th2) {
                    th = th2;
                    IOUtil.closeQuietly(fileChannel2);
                    IOUtil.closeQuietly(fileChannel);
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                fileChannel = fileChannel2;
                fileChannel2 = fileInputStream;
                IOUtil.closeQuietly(fileChannel2);
                IOUtil.closeQuietly(fileChannel);
                throw th;
            }
        } catch (NoSuchAlgorithmException e3) {
            e = e3;
            fileChannel = null;
            throw new RuntimeException(e);
        } catch (Throwable th4) {
            th = th4;
            fileChannel = null;
            IOUtil.closeQuietly(fileChannel2);
            IOUtil.closeQuietly(fileChannel);
            throw th;
        }
    }

    public static String md5(String str) {
        try {
            return toHexString(MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8")));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e2) {
            throw new RuntimeException(e2);
        }
    }
}