what-the-bank/sources/com/huawei/hms/utils/SHA256.java

71 lines
2.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.huawei.hms.utils;
import com.huawei.hms.support.log.HMSLog;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.pqc.jcajce.spec.McElieceCCA2KeyGenParameterSpec;
/* loaded from: classes2.dex */
public abstract class SHA256 {
public static byte[] digest(byte[] bArr) {
try {
return MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA256).digest(bArr);
} catch (NoSuchAlgorithmException e) {
StringBuilder sb = new StringBuilder("NoSuchAlgorithmException");
sb.append(e.getMessage());
HMSLog.e("SHA256", sb.toString());
return new byte[0];
}
}
public static byte[] digest(File file) {
BufferedInputStream bufferedInputStream;
MessageDigest messageDigest;
int i;
BufferedInputStream bufferedInputStream2 = null;
try {
try {
messageDigest = MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA256);
bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
} catch (IOException | NoSuchAlgorithmException unused) {
}
} catch (Throwable th) {
th = th;
bufferedInputStream = bufferedInputStream2;
}
try {
byte[] bArr = new byte[4096];
i = 0;
while (true) {
int read = bufferedInputStream.read(bArr);
if (read == -1) {
break;
}
i += read;
messageDigest.update(bArr, 0, read);
}
} catch (IOException | NoSuchAlgorithmException unused2) {
bufferedInputStream2 = bufferedInputStream;
HMSLog.e("SHA256", "An exception occurred while computing file 'SHA-256'.");
IOUtils.closeQuietly((InputStream) bufferedInputStream2);
return new byte[0];
} catch (Throwable th2) {
th = th2;
IOUtils.closeQuietly((InputStream) bufferedInputStream);
throw th;
}
if (i <= 0) {
IOUtils.closeQuietly((InputStream) bufferedInputStream);
return new byte[0];
}
byte[] digest = messageDigest.digest();
IOUtils.closeQuietly((InputStream) bufferedInputStream);
return digest;
}
}