71 lines
2.4 KiB
Java
71 lines
2.4 KiB
Java
package com.baidu.uaq.agent.android.util;
|
|
|
|
import com.baidu.uaq.agent.android.logging.a;
|
|
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.SecretKeySpec;
|
|
|
|
/* compiled from: EncryptUtil.java */
|
|
/* loaded from: classes.dex */
|
|
public class e {
|
|
static final /* synthetic */ boolean b = !e.class.desiredAssertionStatus();
|
|
private static final a a = com.baidu.uaq.agent.android.logging.b.a();
|
|
|
|
public static String a(String str) throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException {
|
|
if (str != null) {
|
|
return a(a(b("587a0fb0c91ae061e66adbf2ec56f0b8"), str.getBytes()));
|
|
}
|
|
a.b("AES warning: content is null");
|
|
return "";
|
|
}
|
|
|
|
private static byte[] b(String str) {
|
|
int length = str.length() / 2;
|
|
byte[] bArr = new byte[length];
|
|
for (int i = 0; i < length; i++) {
|
|
int i2 = i * 2;
|
|
bArr[i] = Integer.valueOf(str.substring(i2, i2 + 2), 16).byteValue();
|
|
}
|
|
return bArr;
|
|
}
|
|
|
|
private static byte[] a(byte[] bArr, byte[] bArr2) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
|
Cipher a2 = a(1, bArr);
|
|
if (b || a2 != null) {
|
|
return a2.doFinal(bArr2);
|
|
}
|
|
throw new AssertionError();
|
|
}
|
|
|
|
private static Cipher a(int i, byte[] bArr) {
|
|
try {
|
|
Cipher cipher = Cipher.getInstance("AES");
|
|
cipher.init(i, new SecretKeySpec(bArr, "AES"));
|
|
return cipher;
|
|
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static String a(byte[] bArr) {
|
|
if (bArr == null) {
|
|
return "";
|
|
}
|
|
StringBuffer stringBuffer = new StringBuffer(bArr.length * 2);
|
|
for (byte b2 : bArr) {
|
|
a(stringBuffer, b2);
|
|
}
|
|
return stringBuffer.toString();
|
|
}
|
|
|
|
private static void a(StringBuffer stringBuffer, byte b2) {
|
|
stringBuffer.append("0123456789ABCDEF".charAt((b2 >> 4) & 15));
|
|
stringBuffer.append("0123456789ABCDEF".charAt(b2 & 15));
|
|
}
|
|
}
|