65 lines
2.5 KiB
Java
65 lines
2.5 KiB
Java
|
package o;
|
||
|
|
||
|
import java.security.GeneralSecurityException;
|
||
|
import java.security.NoSuchAlgorithmException;
|
||
|
import java.security.spec.InvalidKeySpecException;
|
||
|
import java.util.Arrays;
|
||
|
import javax.crypto.Cipher;
|
||
|
import javax.crypto.SecretKey;
|
||
|
import javax.crypto.SecretKeyFactory;
|
||
|
import javax.crypto.spec.IvParameterSpec;
|
||
|
import javax.crypto.spec.PBEKeySpec;
|
||
|
import javax.crypto.spec.SecretKeySpec;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class wac {
|
||
|
public static SecretKey c(WuW wuW) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||
|
if (wuW == null || !wuW.a()) {
|
||
|
throw new IllegalArgumentException("invalid data for generating the key.");
|
||
|
}
|
||
|
int i = wuW.i;
|
||
|
byte[] b = KzA.b(wuW.d);
|
||
|
byte[] b2 = KzA.b(wuW.e);
|
||
|
return new SecretKeySpec(SecretKeyFactory.getInstance(wuW.c).generateSecret(new PBEKeySpec(KzA.e(d(c(d(c(b, -4), b2), 6), KzA.b(wuW.b))).toCharArray(), KzA.b(wuW.a), wuW.i, wuW.j << 3)).getEncoded(), "AES");
|
||
|
}
|
||
|
|
||
|
private static byte[] d(byte[] bArr, byte[] bArr2) {
|
||
|
if (bArr == null || bArr2 == null) {
|
||
|
throw new NullPointerException("left or right must not be null.");
|
||
|
}
|
||
|
if (bArr.length != bArr2.length) {
|
||
|
throw new IllegalArgumentException("left and right must be the same length.");
|
||
|
}
|
||
|
byte[] bArr3 = new byte[bArr.length];
|
||
|
for (int i = 0; i < bArr.length; i++) {
|
||
|
bArr3[i] = (byte) (bArr[i] ^ bArr2[i]);
|
||
|
}
|
||
|
return bArr3;
|
||
|
}
|
||
|
|
||
|
private static byte[] c(byte[] bArr, int i) {
|
||
|
if (bArr == null) {
|
||
|
throw new NullPointerException("bytes must not be null.");
|
||
|
}
|
||
|
for (int i2 = 0; i2 < bArr.length; i2++) {
|
||
|
if (i < 0) {
|
||
|
bArr[i2] = (byte) (bArr[i2] << (-i));
|
||
|
} else {
|
||
|
bArr[i2] = (byte) (bArr[i2] >> i);
|
||
|
}
|
||
|
}
|
||
|
return bArr;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static byte[] e(SecretKey secretKey, byte[] bArr) throws GeneralSecurityException {
|
||
|
if (secretKey == null || bArr == null) {
|
||
|
throw new NullPointerException("key or cipherText must not be null.");
|
||
|
}
|
||
|
byte[] copyOfRange = Arrays.copyOfRange(bArr, 1, 17);
|
||
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||
|
cipher.init(2, secretKey, new IvParameterSpec(copyOfRange));
|
||
|
return cipher.doFinal(bArr, copyOfRange.length + 1, (bArr.length - copyOfRange.length) - 1);
|
||
|
}
|
||
|
}
|