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

74 lines
2.6 KiB
Java

package o;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.ProviderException;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
/* loaded from: classes2.dex */
public final class iJF implements InterfaceC4280bVg {
private final SecretKey d;
/* JADX INFO: Access modifiers changed from: package-private */
public iJF(String str, KeyStore keyStore) throws GeneralSecurityException {
SecretKey secretKey = (SecretKey) keyStore.getKey(str, null);
this.d = secretKey;
if (secretKey == null) {
throw new InvalidKeyException("Keystore cannot load the key with ID: ".concat(String.valueOf(str)));
}
}
@Override // o.InterfaceC4280bVg
public final byte[] b(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
try {
return a(bArr, bArr2);
} catch (GeneralSecurityException | ProviderException unused) {
try {
Thread.sleep((int) (Math.random() * 100.0d));
} catch (InterruptedException unused2) {
}
return a(bArr, bArr2);
}
}
private byte[] a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
if (bArr.length > 2147483619) {
throw new GeneralSecurityException("plaintext too long");
}
byte[] bArr3 = new byte[bArr.length + 28];
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(1, this.d);
cipher.updateAAD(bArr2);
cipher.doFinal(bArr, 0, bArr.length, bArr3, 12);
System.arraycopy(cipher.getIV(), 0, bArr3, 0, 12);
return bArr3;
}
@Override // o.InterfaceC4280bVg
public final byte[] d(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
try {
return c(bArr, bArr2);
} catch (GeneralSecurityException | ProviderException unused) {
try {
Thread.sleep((int) (Math.random() * 100.0d));
} catch (InterruptedException unused2) {
}
return c(bArr, bArr2);
}
}
private byte[] c(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
if (bArr.length < 28) {
throw new GeneralSecurityException("ciphertext too short");
}
GCMParameterSpec gCMParameterSpec = new GCMParameterSpec(128, bArr, 0, 12);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(2, this.d, gCMParameterSpec);
cipher.updateAAD(bArr2);
return cipher.doFinal(bArr, 12, bArr.length - 12);
}
}