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

179 lines
6.0 KiB
Java

package o;
import android.security.keystore.KeyGenParameterSpec;
import android.text.TextUtils;
import com.google.android.gms.stats.CodePackage;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
/* loaded from: classes2.dex */
public final class gPM {
private static Map<String, SecretKey> b = new HashMap();
public static String a(String str, String str2) {
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
try {
byte[] bytes = str2.getBytes("UTF-8");
byte[] bArr = new byte[0];
if (!TextUtils.isEmpty(str) && bytes != null) {
bArr = e(b(str), bytes);
}
return Yqs.b(bArr);
} catch (UnsupportedEncodingException e) {
e.getMessage();
}
}
return "";
}
private static SecretKey b(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
if (b.get(str) == null) {
c(str);
}
return b.get(str);
}
private static SecretKey c(String str) {
SecretKey secretKey = null;
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
Key key = keyStore.getKey(str, null);
if (!(key instanceof SecretKey)) {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "AndroidKeyStore");
keyGenerator.init(new KeyGenParameterSpec.Builder(str, 3).setBlockModes(CodePackage.GCM).setEncryptionPaddings("NoPadding").setKeySize(256).build());
secretKey = keyGenerator.generateKey();
} else {
secretKey = (SecretKey) key;
}
} catch (IOException e) {
e.getMessage();
} catch (InvalidAlgorithmParameterException e2) {
e2.getMessage();
} catch (KeyStoreException e3) {
e3.getMessage();
} catch (NoSuchAlgorithmException e4) {
e4.getMessage();
} catch (NoSuchProviderException e5) {
e5.getMessage();
} catch (UnrecoverableKeyException e6) {
e6.getMessage();
} catch (CertificateException e7) {
e7.getMessage();
} catch (Exception e8) {
e8.getMessage();
}
b.put(str, secretKey);
return secretKey;
}
public static String e(String str, String str2) {
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
try {
byte[] a = Yqs.a(str2);
byte[] bArr = new byte[0];
if (!TextUtils.isEmpty(str) && a.length > 12) {
bArr = a(b(str), a);
}
return new String(bArr, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.getMessage();
}
}
return "";
}
private static byte[] e(SecretKey secretKey, byte[] bArr) {
byte[] bArr2 = new byte[0];
if (bArr == null || secretKey == null) {
return bArr2;
}
try {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(1, secretKey);
byte[] doFinal = cipher.doFinal(bArr);
byte[] iv = cipher.getIV();
if (iv != null && iv.length == 12) {
bArr2 = Arrays.copyOf(iv, iv.length + doFinal.length);
System.arraycopy(doFinal, 0, bArr2, iv.length, doFinal.length);
return bArr2;
}
return bArr2;
} catch (InvalidKeyException e) {
e.getMessage();
return bArr2;
} catch (NoSuchAlgorithmException e2) {
e2.getMessage();
return bArr2;
} catch (BadPaddingException e3) {
e3.getMessage();
return bArr2;
} catch (IllegalBlockSizeException e4) {
e4.getMessage();
return bArr2;
} catch (NoSuchPaddingException e5) {
e5.getMessage();
return bArr2;
} catch (Exception e6) {
e6.getMessage();
return bArr2;
}
}
private static byte[] a(SecretKey secretKey, byte[] bArr) {
byte[] bArr2 = new byte[0];
if (secretKey == null || bArr == null || bArr.length <= 12) {
return bArr2;
}
byte[] copyOf = Arrays.copyOf(bArr, 12);
try {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(2, secretKey, new GCMParameterSpec(128, copyOf));
return cipher.doFinal(bArr, 12, bArr.length - 12);
} catch (InvalidAlgorithmParameterException e) {
e.getMessage();
return bArr2;
} catch (InvalidKeyException e2) {
e2.getMessage();
return bArr2;
} catch (NoSuchAlgorithmException e3) {
e3.getMessage();
return bArr2;
} catch (BadPaddingException e4) {
e4.getMessage();
return bArr2;
} catch (IllegalBlockSizeException e5) {
e5.getMessage();
return bArr2;
} catch (NoSuchPaddingException e6) {
e6.getMessage();
return bArr2;
} catch (Exception e7) {
e7.getMessage();
return bArr2;
}
}
}