what-the-bank/sources/o/fOS.java

253 lines
8.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package o;
import android.os.Build;
import android.util.Base64;
import com.huawei.hms.android.HwBuildEx;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
/* loaded from: classes.dex */
public final class fOS {
private static AtomicBoolean e = new AtomicBoolean(false);
public static LWm e(String str) throws InvalidKeyException {
String[] split = str.split(":");
if (split.length != 2) {
throw new IllegalArgumentException("Cannot parse aesKey:hmacKey");
}
byte[] decode = Base64.decode(split[0], 2);
if (decode.length != 16) {
throw new InvalidKeyException("Base64 decoded key is not 128 bytes");
}
byte[] decode2 = Base64.decode(split[1], 2);
if (decode2.length != 32) {
throw new InvalidKeyException("Base64 decoded key is not 256 bytes");
}
return new LWm(new SecretKeySpec(decode, 0, decode.length, "AES"), new SecretKeySpec(decode2, "HmacSHA256"));
}
public static LWm c() throws GeneralSecurityException {
a();
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128);
return new LWm(keyGenerator.generateKey(), new SecretKeySpec(a(32), "HmacSHA256"));
}
public static LWm d(String str, byte[] bArr, int i) throws GeneralSecurityException {
a();
byte[] encoded = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(str.toCharArray(), bArr, HwBuildEx.VersionCodes.CUR_DEVELOPMENT, 384)).getEncoded();
byte[] bArr2 = new byte[16];
System.arraycopy(encoded, 0, bArr2, 0, 16);
byte[] bArr3 = new byte[32];
System.arraycopy(encoded, 16, bArr3, 0, 32);
return new LWm(new SecretKeySpec(bArr2, "AES"), new SecretKeySpec(bArr3, "HmacSHA256"));
}
private static byte[] a(int i) throws GeneralSecurityException {
a();
byte[] bArr = new byte[i];
new SecureRandom().nextBytes(bArr);
return bArr;
}
public static RVV d(String str, LWm lWm) throws UnsupportedEncodingException, GeneralSecurityException {
byte[] bytes = str.getBytes("UTF-8");
byte[] a = a(16);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(1, lWm.a, new IvParameterSpec(a));
byte[] iv = cipher.getIV();
byte[] doFinal = cipher.doFinal(bytes);
byte[] bArr = new byte[iv.length + doFinal.length];
System.arraycopy(iv, 0, bArr, 0, iv.length);
System.arraycopy(doFinal, 0, bArr, iv.length, doFinal.length);
SecretKey secretKey = lWm.e;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKey);
return new RVV(doFinal, iv, mac.doFinal(bArr));
}
private static void a() {
AtomicBoolean atomicBoolean = e;
if (atomicBoolean.get()) {
return;
}
synchronized (Sts.class) {
if (!atomicBoolean.get()) {
Sts.e();
atomicBoolean.set(true);
}
}
}
/* loaded from: classes.dex */
public static class LWm {
SecretKey a;
SecretKey e;
public LWm(SecretKey secretKey, SecretKey secretKey2) {
this.a = secretKey;
this.e = secretKey2;
}
public final String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Base64.encodeToString(this.a.getEncoded(), 2));
sb.append(":");
sb.append(Base64.encodeToString(this.e.getEncoded(), 2));
return sb.toString();
}
public final int hashCode() {
return ((this.a.hashCode() + 31) * 31) + this.e.hashCode();
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
LWm lWm = (LWm) obj;
return this.e.equals(lWm.e) && this.a.equals(lWm.a);
}
}
/* loaded from: classes.dex */
public static class RVV {
final byte[] c;
final byte[] d;
final byte[] e;
public RVV(byte[] bArr, byte[] bArr2, byte[] bArr3) {
byte[] bArr4 = new byte[bArr.length];
this.d = bArr4;
System.arraycopy(bArr, 0, bArr4, 0, bArr.length);
byte[] bArr5 = new byte[bArr2.length];
this.c = bArr5;
System.arraycopy(bArr2, 0, bArr5, 0, bArr2.length);
byte[] bArr6 = new byte[bArr3.length];
this.e = bArr6;
System.arraycopy(bArr3, 0, bArr6, 0, bArr3.length);
}
public RVV(String str) {
String[] split = str.split(":");
if (split.length != 3) {
throw new IllegalArgumentException("Cannot parse iv:ciphertext:mac");
}
this.c = Base64.decode(split[0], 2);
this.e = Base64.decode(split[1], 2);
this.d = Base64.decode(split[2], 2);
}
public final String toString() {
String encodeToString = Base64.encodeToString(this.c, 2);
String encodeToString2 = Base64.encodeToString(this.d, 2);
String encodeToString3 = Base64.encodeToString(this.e, 2);
StringBuilder sb = new StringBuilder();
sb.append(encodeToString);
sb.append(":");
sb.append(encodeToString3);
sb.append(":");
sb.append(encodeToString2);
return String.format(sb.toString(), new Object[0]);
}
public final int hashCode() {
int hashCode = Arrays.hashCode(this.d);
return ((((hashCode + 31) * 31) + Arrays.hashCode(this.c)) * 31) + Arrays.hashCode(this.e);
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
RVV rvv = (RVV) obj;
return Arrays.equals(this.d, rvv.d) && Arrays.equals(this.c, rvv.c) && Arrays.equals(this.e, rvv.e);
}
}
/* loaded from: classes.dex */
public static final class Sts {
public static void e() {
}
static {
d();
}
private Sts() {
}
private static String a() {
try {
return (String) Build.class.getField("SERIAL").get(null);
} catch (Exception unused) {
return null;
}
}
private static byte[] d() {
StringBuilder sb = new StringBuilder();
String str = Build.FINGERPRINT;
if (str != null) {
sb.append(str);
}
String a = a();
if (a != null) {
sb.append(a);
}
try {
return sb.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException unused) {
throw new RuntimeException("UTF-8 encoding not supported");
}
}
}
private static byte[] c(RVV rvv, LWm lWm) throws GeneralSecurityException {
byte[] bArr = rvv.c;
byte[] bArr2 = rvv.d;
byte[] bArr3 = new byte[bArr.length + bArr2.length];
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
SecretKey secretKey = lWm.e;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKey);
byte[] doFinal = mac.doFinal(bArr3);
byte[] bArr4 = rvv.e;
if (doFinal.length == bArr4.length) {
int i = 0;
for (int i2 = 0; i2 < doFinal.length; i2++) {
i |= doFinal[i2] ^ bArr4[i2];
}
if (i == 0) {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(2, lWm.a, new IvParameterSpec(rvv.c));
return cipher.doFinal(rvv.d);
}
}
throw new GeneralSecurityException("MAC stored in civ does not match computed MAC.");
}
public static String d(RVV rvv, LWm lWm) throws UnsupportedEncodingException, GeneralSecurityException {
return new String(c(rvv, lWm), "UTF-8");
}
}