package o; import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.KeyFactory; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Provider; import java.security.PublicKey; import java.security.SecureRandom; import java.security.Security; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidKeySpecException; import java.security.spec.MGF1ParameterSpec; import java.security.spec.RSAPublicKeySpec; import java.util.Arrays; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESedeKeySpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.OAEPParameterSpec; import javax.crypto.spec.PSource; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.pqc.jcajce.spec.McElieceCCA2KeyGenParameterSpec; /* loaded from: classes3.dex */ public final class VBO { private static final IvParameterSpec c; private static final IvParameterSpec e; static { String property; Ymn.d("secret00"); try { if (Security.getProvider("SunJCE") == null) { Security.addProvider((Provider) Class.forName("com.sun.crypto.provider.SunJCE").newInstance()); } } catch (Throwable unused) { } try { if (Security.getProvider("IBMJCE") == null) { Security.addProvider((Provider) Class.forName("com.ibm.crypto.provider.IBMJCE").newInstance()); } } catch (Throwable unused2) { } try { if (Security.getProvider("IBMJCA") == null) { Security.addProvider((Provider) Class.forName("com.ibm.crypto.provider.IBMJCA").newInstance()); } } catch (Throwable unused3) { } try { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider((Provider) Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance()); } } catch (Throwable unused4) { } try { if (Security.getProvider("SM") == null) { Security.addProvider((Provider) Class.forName("cn.wind.smjce.jce.provider.SMProvider").newInstance()); } } catch (Throwable unused5) { } for (int i = 1; i <= 100 && (property = System.getProperty("isprint.security.provider.".concat(String.valueOf(i)))) != null && property.length() >= 0; i++) { try { Security.addProvider((Provider) Class.forName(property).newInstance()); } catch (Throwable unused6) { } } e = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0}); c = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); new SecureRandom(); } public static byte[] d(int i) { byte[] bArr = new byte[i]; new SecureRandom().nextBytes(bArr); return bArr; } public static byte[] e(String str, byte[] bArr) throws NoSuchAlgorithmException { MessageDigest messageDigest = MessageDigest.getInstance(str); messageDigest.update(bArr); return messageDigest.digest(); } public static byte[] b(byte[] bArr) { try { MessageDigest messageDigest = MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA1); messageDigest.update(bArr); return messageDigest.digest(); } catch (NoSuchAlgorithmException e2) { throw new RuntimeException(e2); } } public static Key e(byte[] bArr) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException { if (bArr.length == 16) { byte[] bArr2 = new byte[24]; System.arraycopy(bArr, 0, bArr2, 0, 16); System.arraycopy(bArr, 0, bArr2, 16, 8); bArr = bArr2; } return SecretKeyFactory.getInstance("DESede").generateSecret(new DESedeKeySpec(bArr)); } private static IvParameterSpec d(byte[] bArr, int i) { if (bArr == null || bArr.length == 0) { if (i == 8) { return e; } if (i == 16) { return c; } bArr = new byte[i]; } else if (bArr.length < i) { bArr = c(bArr, i); } return new IvParameterSpec(bArr, 0, i); } private static OAEPParameterSpec b(byte[] bArr, String str, String str2) { if (bArr == null || bArr.length == 0) { return OAEPParameterSpec.DEFAULT; } if (str == null) { str = OAEPParameterSpec.DEFAULT.getDigestAlgorithm(); } AlgorithmParameterSpec mGFParameters = OAEPParameterSpec.DEFAULT.getMGFParameters(); if (str2 != null) { mGFParameters = new MGF1ParameterSpec(str2); } return new OAEPParameterSpec(str, OAEPParameterSpec.DEFAULT.getMGFAlgorithm(), mGFParameters, new PSource.PSpecified(bArr)); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public static class RVV { private static String[] d = {"/OAEPWithSHA256AndMGF1Padding", McElieceCCA2KeyGenParameterSpec.SHA256, "/OAEPWithSHA-256AndMGF1Padding", "/OAEPWithSHA1AndMGF1Padding", McElieceCCA2KeyGenParameterSpec.SHA1, "/OAEPWithSHA-1AndMGF1Padding", "/OAEPWithSHA512AndMGF1Padding", McElieceCCA2KeyGenParameterSpec.SHA512, "/OAEPWithSHA-512AndMGF1Padding"}; String a; private String b; String c; boolean e; RVV(String str) { int i = 0; while (true) { String[] strArr = d; if (i >= strArr.length) { return; } String str2 = strArr[i]; String str3 = strArr[i + 1]; String str4 = strArr[i + 2]; if (str.endsWith(str2)) { StringBuilder sb = new StringBuilder(); sb.append(str.substring(0, str.length() - str2.length())); sb.append(str4); this.c = sb.toString(); this.a = str3; this.b = null; this.e = true; return; } i += 3; } } public final String toString() { StringBuilder sb = new StringBuilder("(OAEP "); sb.append(this.e); sb.append(' '); sb.append(this.b); sb.append(' '); sb.append(this.c); sb.append(" digest="); sb.append(this.a); sb.append(')'); return sb.toString(); } } public static byte[] b(Key key, byte[] bArr, String str, byte[] bArr2) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException { RVV rvv = new RVV(str); if (rvv.e) { str = rvv.c; } Cipher cipher = Cipher.getInstance(str); if (str.indexOf("/OAEPWithSHA1AndMGF1Padding") >= 0) { cipher.init(1, key, b(bArr2, null, null)); } else if (rvv.e) { cipher.init(1, key, b(bArr2, rvv.a, rvv.a)); } else if (str.indexOf("/ECB") >= 0 || str.indexOf("/SSL") >= 0 || str.indexOf("/NONE") >= 0 || str.indexOf(47) < 0) { cipher.init(1, key); } else { cipher.init(1, key, d(bArr2, cipher.getBlockSize())); } return cipher.doFinal(bArr); } private static byte[] c(byte[] bArr, int i) { if (bArr.length == i) { return bArr; } byte[] bArr2 = new byte[i]; for (int i2 = 0; i2 < bArr.length && i2 < i; i2++) { bArr2[i2] = bArr[i2]; } return bArr2; } public static PublicKey e(String str) throws NoSuchAlgorithmException, InvalidKeySpecException { String[] split = str.split(",", 2); return KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(new BigInteger(1, Ymn.a(split[0])), new BigInteger(1, Ymn.a(split[1])))); } public static byte[] b(byte[] bArr, byte[] bArr2) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException { if (bArr.length != 16 && bArr.length != 24) { throw new InvalidKeyException(); } byte[] bArr3 = new byte[8]; c(bArr3, 8); byte[] e2 = e(bArr, 0, 8); Key e3 = e(e2); Key e4 = e(e(bArr, 8, 16)); if (bArr.length == 24) { e2 = e(bArr, 16, 24); } Key e5 = e(e2); byte[] bArr4 = new byte[8]; byte[] bArr5 = new byte[8]; int length = bArr2.length; int i = 0; while (length >= 8) { System.arraycopy(bArr2, i, bArr4, 0, 8); bArr5 = b(e3, C17821zzv.a(bArr4, bArr5, Math.min(8, bArr5.length)), "DESede/CBC/NoPadding", bArr3); length -= 8; i += 8; } System.arraycopy(bArr2, i, bArr4, 0, length); Arrays.fill(bArr4, length, 8, (byte) 0); byte[] b = b(e3, C17821zzv.a(bArr4, bArr5, Math.min(8, bArr5.length)), "DESede/CBC/NoPadding", bArr3); RVV rvv = new RVV("DESede/CBC/NoPadding"); String str = rvv.e ? rvv.c : "DESede/CBC/NoPadding"; Cipher cipher = Cipher.getInstance(str); if (str.indexOf("/OAEPWithSHA1AndMGF1Padding") >= 0) { cipher.init(2, e4, b(bArr3, null, null)); } else if (rvv.e) { cipher.init(2, e4, b(bArr3, rvv.a, rvv.a)); } else if (str.indexOf("/ECB") >= 0 || str.indexOf("/SSL") >= 0 || str.indexOf("/NONE") >= 0 || str.indexOf(47) < 0) { cipher.init(2, e4); } else { cipher.init(2, e4, d(bArr3, cipher.getBlockSize())); } return b(e5, cipher.doFinal(b), "DESede/CBC/NoPadding", bArr3); } private static byte[] e(byte[] bArr, int i, int i2) { byte[] bArr2 = new byte[24]; int i3 = i2 - i; for (int i4 = 0; i4 < 24; i4 += i3) { System.arraycopy(bArr, i, bArr2, i4, Math.min(i3, 24 - i4)); } return bArr2; } }