package a4; import android.content.Context; import android.util.Base64; import android.util.Log; import com.google.android.gms.internal.p002firebaseauthapi.zzbf; import com.google.android.gms.internal.p002firebaseauthapi.zzbk; import com.google.android.gms.internal.p002firebaseauthapi.zzcb; import com.google.android.gms.internal.p002firebaseauthapi.zzio; import com.google.android.gms.internal.p002firebaseauthapi.zzit; import com.google.android.gms.internal.p002firebaseauthapi.zzjr; import com.google.android.gms.internal.p002firebaseauthapi.zzjt; import com.google.android.gms.internal.p002firebaseauthapi.zzly; import com.google.android.gms.internal.p002firebaseauthapi.zzq; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; /* loaded from: classes2.dex */ public final class r0 { /* renamed from: c, reason: collision with root package name */ private static r0 f121c; /* renamed from: a, reason: collision with root package name */ private final String f122a; /* renamed from: b, reason: collision with root package name */ private final zzjt f123b; private r0(Context context, String str, boolean z10) { zzjt zzjtVar; this.f122a = str; try { zzio.zza(); zzjr zzjrVar = new zzjr(); zzjrVar.zzf(context, "GenericIdpKeyset", String.format("com.google.firebase.auth.api.crypto.%s", str)); zzjrVar.zzd(zzit.zza); zzjrVar.zze(String.format("android-keystore://firebear_master_key_id.%s", str)); zzjtVar = zzjrVar.zzg(); } catch (IOException | GeneralSecurityException e10) { Log.e("FirebearCryptoHelper", "Exception encountered during crypto setup:\n".concat(String.valueOf(e10.getMessage()))); zzjtVar = null; } this.f123b = zzjtVar; } public static r0 a(Context context, String str) { r0 r0Var = f121c; if (r0Var == null || !zzq.zza(r0Var.f122a, str)) { f121c = new r0(context, str, true); } return f121c; } public final String b(String str) { String str2; zzjt zzjtVar = this.f123b; if (zzjtVar == null) { Log.e("FirebearCryptoHelper", "KeysetManager failed to initialize - unable to decrypt payload"); return null; } try { synchronized (zzjtVar) { str2 = new String(((zzbk) this.f123b.zza().zze(zzly.zza(), zzbk.class)).zza(Base64.decode(str, 8), null), "UTF-8"); } return str2; } catch (UnsupportedEncodingException | GeneralSecurityException e10) { Log.e("FirebearCryptoHelper", "Exception encountered while decrypting bytes:\n".concat(String.valueOf(e10.getMessage()))); return null; } } public final String c() { if (this.f123b == null) { Log.e("FirebearCryptoHelper", "KeysetManager failed to initialize - unable to get Public key"); return null; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zzcb zza = zzbf.zza(byteArrayOutputStream); try { synchronized (this.f123b) { this.f123b.zza().zzb().zzg(zza); } return Base64.encodeToString(byteArrayOutputStream.toByteArray(), 8); } catch (IOException | GeneralSecurityException e10) { Log.e("FirebearCryptoHelper", "Exception encountered when attempting to get Public Key:\n".concat(String.valueOf(e10.getMessage()))); return null; } } }