package com.google.android.gms.internal.ads;

import java.nio.ByteBuffer;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/* JADX INFO: loaded from: classes2.dex */
public final class km1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static Cipher f13314a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Object f13315b = new Object();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Object f13316c = new Object();

    public static byte[] a(String str, byte[] bArr) throws zzgfv {
        byte[] bArrDoFinal;
        int length = bArr.length;
        try {
            byte[] bArrJ0 = ih1.j0(str, false);
            int length2 = bArrJ0.length;
            if (length2 <= 16) {
                throw new zzgfv();
            }
            ByteBuffer byteBufferAllocate = ByteBuffer.allocate(length2);
            byteBufferAllocate.put(bArrJ0);
            byteBufferAllocate.flip();
            byte[] bArr2 = new byte[16];
            byte[] bArr3 = new byte[length2 - 16];
            byteBufferAllocate.get(bArr2);
            byteBufferAllocate.get(bArr3);
            SecretKeySpec secretKeySpec = new SecretKeySpec(bArr, "AES");
            synchronized (f13315b) {
                b().init(2, secretKeySpec, new IvParameterSpec(bArr2));
                bArrDoFinal = b().doFinal(bArr3);
            }
            return bArrDoFinal;
        } catch (IllegalArgumentException e10) {
            e = e10;
            throw new zzgfv(e);
        } catch (InvalidAlgorithmParameterException e11) {
            e = e11;
            throw new zzgfv(e);
        } catch (InvalidKeyException e12) {
            e = e12;
            throw new zzgfv(e);
        } catch (NoSuchAlgorithmException e13) {
            e = e13;
            throw new zzgfv(e);
        } catch (BadPaddingException e14) {
            e = e14;
            throw new zzgfv(e);
        } catch (IllegalBlockSizeException e15) {
            e = e15;
            throw new zzgfv(e);
        } catch (NoSuchPaddingException e16) {
            e = e16;
            throw new zzgfv(e);
        }
    }

    public static final Cipher b() {
        Cipher cipher;
        synchronized (f13316c) {
            try {
                if (f13314a == null) {
                    f13314a = Cipher.getInstance("AES/CBC/PKCS5Padding");
                }
                cipher = f13314a;
            } catch (Throwable th) {
                throw th;
            }
        }
        return cipher;
    }
}
