|
package com.example.myapplication;
import android.text.TextUtils;
import android.util.Base64;
import com.example.myapplication.cm;
import com.example.myapplication.ByteTransformUtils;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AesCrypto {
/* renamed from: a reason: collision with root package name */
public static final String f4604a = "df0b".toLowerCase();
public static final byte[] b = Base64.decode("VlEc5qsEDXWChrWJ0AzMXQ==", 2);
/* renamed from: c reason: collision with root package name */
public static final byte[] f4605c = Base64.decode("MC8Lpxk9zqyuRPXMdO8rJQ==", 2);
public static final byte[] d = a();
private static byte[] b(byte[] bArr) throws Exception {
return bArr;
}
public static String a(String str, byte[] bArr) throws Exception {
return a(a(b(b), str.getBytes(), bArr));
}
public static String a(String str) throws Exception {
byte[] a2 = a();
String a3 = a(str, a2);
String a4 = a(a2);
int parseInt = Integer.parseInt(f4604a.substring(0, 1), 16);
return f4604a + a3.substring(0, parseInt) + a4 + a3.substring(parseInt);
}
public static String b(String str) throws Exception {
return b(str, f4604a, b);
}
public static String c(String str) throws Exception {
return a(str, f4604a, b);
}
public static String d(String str) throws Exception {
return b(str, "4545", f4605c);
}
public static String e(String str) throws Exception {
return a(str, "4545", f4605c);
}
private static String a(String str, String str2, byte[] bArr) throws Exception {
if (TextUtils.isEmpty(str)) {
return "";
}
byte[] decode = Base64.decode(str, 2);
String lowerCase = ByteTransformUtils.a(decode, 0, decode.length).toLowerCase();
if (lowerCase.startsWith(str2)) {
lowerCase = lowerCase.substring(str2.length());
}
int parseInt = Integer.parseInt(str2.substring(0, 1), 16);
int i = parseInt + 32;
String substring = lowerCase.substring(parseInt, i);
return new String(b(b(bArr), f(lowerCase.substring(0, parseInt) + lowerCase.substring(i)), ByteTransformUtils.a(substring)));
}
private static String b(String str, String str2, byte[] bArr) throws Exception {
byte[] a2 = a();
String a3 = a(a(b(bArr), str.getBytes(), a2));
String a4 = a(a2);
int parseInt = Integer.parseInt(str2.substring(0, 1), 16);
return Base64.encodeToString(ByteTransformUtils.a(str2 + a3.substring(0, parseInt) + a4 + a3.substring(parseInt)), 2);
}
private static byte[] a(byte[] bArr, byte[] bArr2, byte[] bArr3) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(bArr, "AES");
Cipher instance = Cipher.getInstance("AES/CBC/PKCS7Padding");
instance.init(1, secretKeySpec, new IvParameterSpec(bArr3));
return instance.doFinal(bArr2);
}
private static byte[] b(byte[] bArr, byte[] bArr2, byte[] bArr3) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(bArr, "AES");
Cipher instance = Cipher.getInstance("AES/CBC/PKCS7Padding");
instance.init(2, secretKeySpec, new IvParameterSpec(bArr3));
return instance.doFinal(bArr2);
}
public static byte[] f(String str) {
int length = str.length() / 2;
byte[] bArr = new byte[length];
for (int i = 0; i < length; i++) {
int i2 = i * 2;
bArr = Integer.valueOf(str.substring(i2, i2 + 2), 16).byteValue();
}
return bArr;
}
public 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 & cm.m));
}
private static byte[] a() {
Random random = new Random();
byte[] bArr = new byte[16];
for (int i = 0; i < 16; i++) {
bArr = (byte) (random.nextInt(256) - 128);
}
return bArr;
}
}
import android.text.TextUtils;
import android.util.Base64;
这两个安卓的包,能翻译成JAVA的包吗,想做成一个工具类
|
|