package o; import android.content.Context; import android.content.res.Configuration; import android.security.keystore.KeyGenParameterSpec; import java.math.BigInteger; import java.security.Key; import java.security.KeyPairGenerator; import java.security.KeyStore; import java.security.PrivateKey; import java.security.PublicKey; import java.security.cert.Certificate; import java.security.spec.AlgorithmParameterSpec; import java.util.Calendar; import java.util.Locale; import javax.crypto.Cipher; import javax.security.auth.x500.X500Principal; import org.bouncycastle.pqc.jcajce.spec.McElieceCCA2KeyGenParameterSpec; /* renamed from: o.jEc, reason: case insensitive filesystem */ /* loaded from: classes3.dex */ class C15855jEc implements zVr { protected final String a; protected final Context d; protected AlgorithmParameterSpec d() { return null; } public C15855jEc(Context context) throws Exception { this.d = context; String c = c(); this.a = c; KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); keyStore.load(null); if (keyStore.getKey(c, null) == null) { Locale locale = Locale.getDefault(); try { Locale locale2 = Locale.ENGLISH; Locale.setDefault(locale2); Configuration configuration = context.getResources().getConfiguration(); configuration.setLocale(locale2); context.createConfigurationContext(configuration); Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar2.add(1, 25); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore"); keyPairGenerator.initialize(c(calendar, calendar2)); keyPairGenerator.generateKeyPair(); Locale.setDefault(locale); Configuration configuration2 = context.getResources().getConfiguration(); configuration2.setLocale(locale); context.createConfigurationContext(configuration2); } catch (Throwable th) { Locale.setDefault(locale); Configuration configuration3 = this.d.getResources().getConfiguration(); configuration3.setLocale(locale); this.d.createConfigurationContext(configuration3); throw th; } } } protected String c() { StringBuilder sb = new StringBuilder(); sb.append(this.d.getPackageName()); sb.append(".FlutterSecureStoragePluginKey"); return sb.toString(); } protected Cipher a() throws Exception { return Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidKeyStoreBCWorkaround"); } protected AlgorithmParameterSpec c(Calendar calendar, Calendar calendar2) { KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(this.a, 3); StringBuilder sb = new StringBuilder("CN="); sb.append(this.a); return builder.setCertificateSubject(new X500Principal(sb.toString())).setDigests(McElieceCCA2KeyGenParameterSpec.SHA256).setBlockModes("ECB").setEncryptionPaddings("PKCS1Padding").setCertificateSerialNumber(BigInteger.valueOf(1L)).setCertificateNotBefore(calendar.getTime()).setCertificateNotAfter(calendar2.getTime()).build(); } @Override // o.zVr public Key c(byte[] bArr, String str) throws Exception { KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); keyStore.load(null); Key key = keyStore.getKey(this.a, null); if (key == null) { StringBuilder sb = new StringBuilder("No key found under alias: "); sb.append(this.a); throw new Exception(sb.toString()); } if (key instanceof PrivateKey) { Cipher a = a(); a.init(4, (PrivateKey) key, d()); return a.unwrap(bArr, str, 3); } throw new Exception("Not an instance of a PrivateKey"); } @Override // o.zVr public byte[] a(Key key) throws Exception { KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); keyStore.load(null); Certificate certificate = keyStore.getCertificate(this.a); if (certificate == null) { StringBuilder sb = new StringBuilder("No certificate found under alias: "); sb.append(this.a); throw new Exception(sb.toString()); } PublicKey publicKey = certificate.getPublicKey(); if (publicKey != null) { Cipher a = a(); a.init(3, publicKey, d()); return a.wrap(key); } StringBuilder sb2 = new StringBuilder("No key found under alias: "); sb2.append(this.a); throw new Exception(sb2.toString()); } }