package com.huawei.hms.hatool; import android.util.Pair; import java.nio.charset.Charset; import java.security.SecureRandom; import o.BAC; import o.JyG; import o.YkQ; import o.Yqs; /* loaded from: classes2.dex */ public class n { public static final Charset a = Charset.forName("UTF-8"); public static String a(byte[] bArr, String str) { String str2; byte[] bArr2; if (bArr == null || bArr.length == 0 || str == null) { str2 = "cbc encrypt(byte) param is not right"; } else { byte[] a2 = Yqs.a(str); if (a2.length >= 16) { SecureRandom d = BAC.d(); if (d == null) { bArr2 = new byte[0]; } else { byte[] bArr3 = new byte[12]; d.nextBytes(bArr3); bArr2 = bArr3; } byte[] b = YkQ.b(bArr, a2, bArr2); byte[] bArr4 = new byte[bArr2.length + b.length]; System.arraycopy(bArr2, 0, bArr4, 0, bArr2.length); System.arraycopy(b, 0, bArr4, bArr2.length, b.length); return Yqs.b(bArr4); } str2 = "key length is not right"; } v.b("AesCipher", str2); return ""; } public static String b(String str, String str2) { byte[] bArr; byte[] bytes = str.getBytes(a); byte[] a2 = Yqs.a(str2); SecureRandom d = BAC.d(); if (d == null) { bArr = new byte[0]; } else { byte[] bArr2 = new byte[16]; d.nextBytes(bArr2); bArr = bArr2; } byte[] a3 = JyG.a(bytes, a2, bArr); byte[] bArr3 = new byte[bArr.length + a3.length]; System.arraycopy(bArr, 0, bArr3, 0, bArr.length); System.arraycopy(a3, 0, bArr3, bArr.length, a3.length); return Yqs.b(bArr3); } public static String a(String str, String str2) { Pair a2 = a(str, 32); return new String(JyG.b(Yqs.a((String) a2.second), Yqs.a(str2), (byte[]) a2.first), a); } public static Pair a(String str, int i) { if (str == null || str.length() < i) { return new Pair<>(new byte[0], str); } String substring = str.substring(0, i); return new Pair<>(Yqs.a(substring), str.substring(i)); } }