what-the-bank/sources/com/pingan/ai/w.java

72 lines
2.8 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.pingan.ai;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
/* loaded from: classes3.dex */
public final class w {
public static byte[] a(byte[] bArr, byte[] bArr2, int i, String str) {
return a(bArr, bArr2, i, str, true);
}
public static byte[] a(byte[] bArr, byte[] bArr2, int i, String str, boolean z) {
Key generatePrivate;
if (bArr != null && bArr.length != 0 && bArr2 != null && bArr2.length != 0) {
try {
if (z) {
generatePrivate = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bArr2));
} else {
generatePrivate = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(bArr2));
}
if (generatePrivate == null) {
return null;
}
Cipher cipher = Cipher.getInstance(str);
cipher.init(z ? 1 : 2, generatePrivate);
int length = bArr.length;
int i2 = i / 8;
if (z && str.toLowerCase().endsWith("pkcs1padding")) {
i2 -= 11;
}
int i3 = length / i2;
if (i3 > 0) {
byte[] bArr3 = new byte[0];
byte[] bArr4 = new byte[i2];
int i4 = 0;
for (int i5 = 0; i5 < i3; i5++) {
System.arraycopy(bArr, i4, bArr4, 0, i2);
bArr3 = a(bArr3, cipher.doFinal(bArr4));
i4 += i2;
}
if (i4 == length) {
return bArr3;
}
int i6 = length - i4;
byte[] bArr5 = new byte[i6];
System.arraycopy(bArr, i4, bArr5, 0, i6);
return a(bArr3, cipher.doFinal(bArr5));
}
return cipher.doFinal(bArr);
} catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException unused) {
}
}
return null;
}
public static byte[] a(byte[] bArr, byte[] bArr2) {
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);
return bArr3;
}
}