mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-28 06:31:15 +00:00
Fixed code style
This commit is contained in:
+12
-13
@@ -32,8 +32,8 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class HarmanBinaryDataEncrypt {
|
||||
|
||||
private static final String GLOBAL_KEY = "Adobe AIR SDK (c) 2021 HARMAN Internation Industries Incorporated";
|
||||
|
||||
private static final String GLOBAL_KEY = "Adobe AIR SDK (c) 2021 HARMAN Internation Industries Incorporated";
|
||||
|
||||
public static byte[] encrypt(byte[] data) {
|
||||
byte[] result;
|
||||
try {
|
||||
@@ -51,14 +51,13 @@ public class HarmanBinaryDataEncrypt {
|
||||
random.nextBytes(keyBytes);
|
||||
long random1 = unpack(randomBytes1, 0);
|
||||
long random2 = unpack(randomBytes2, 0);
|
||||
|
||||
|
||||
|
||||
byte[] ivBytes = getIv(hashBytes, random1, random2);
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
||||
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
|
||||
byte[] dataPadded = new byte[(int) encryptedDataLen];
|
||||
random.nextBytes(dataPadded);
|
||||
System.arraycopy(data, 0, dataPadded, 0, data.length);
|
||||
System.arraycopy(data, 0, dataPadded, 0, data.length);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
|
||||
@@ -71,14 +70,14 @@ public class HarmanBinaryDataEncrypt {
|
||||
System.arraycopy(pack(dataLenXorRandom1), 0, result, 4, 4);
|
||||
System.arraycopy(randomBytes1, 0, result, 8, 4);
|
||||
System.arraycopy(randomBytes2, 0, result, 12, 4);
|
||||
|
||||
|
||||
addBytes(keyBytes, 0, randomBytes2, 1);
|
||||
addBytes(keyBytes, 4, randomBytes2, -1);
|
||||
addBytes(keyBytes, 8, randomBytes2, 1);
|
||||
addBytes(keyBytes, 12, randomBytes2, -1);
|
||||
|
||||
System.arraycopy(keyBytes, 0, result, 16, 16);
|
||||
System.arraycopy(encryptedBytes, 0, result, 32, encryptedDataLen);
|
||||
System.arraycopy(encryptedBytes, 0, result, 32, encryptedDataLen);
|
||||
} catch (UnsupportedEncodingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException ex) {
|
||||
result = null;
|
||||
}
|
||||
@@ -138,14 +137,14 @@ public class HarmanBinaryDataEncrypt {
|
||||
if (data.length < 32) {
|
||||
return null;
|
||||
}
|
||||
long encryptedLen = data.length;
|
||||
long encryptedLen = data.length;
|
||||
long encryptedLenXorHash = unpack(data, 0);
|
||||
long decryptedLenXorRandom1 = unpack(data, 4);
|
||||
|
||||
long random1 = unpack(data, 8);
|
||||
long random2 = unpack(data, 12);
|
||||
byte[] random2Bytes = Arrays.copyOfRange(data, 12, 16);
|
||||
byte[] keyBytes = Arrays.copyOfRange(data, 16, 32);
|
||||
byte[] random2Bytes = Arrays.copyOfRange(data, 12, 16);
|
||||
byte[] keyBytes = Arrays.copyOfRange(data, 16, 32);
|
||||
byte[] encryptedBytes = Arrays.copyOfRange(data, 32, data.length);
|
||||
|
||||
long decryptedLen = decryptedLenXorRandom1 ^ random1;
|
||||
@@ -154,7 +153,7 @@ public class HarmanBinaryDataEncrypt {
|
||||
addBytes(keyBytes, 0, random2Bytes, -1);
|
||||
addBytes(keyBytes, 4, random2Bytes, 1);
|
||||
addBytes(keyBytes, 8, random2Bytes, -1);
|
||||
addBytes(keyBytes, 12, random2Bytes, 1);
|
||||
addBytes(keyBytes, 12, random2Bytes, 1);
|
||||
|
||||
try {
|
||||
byte[] ivBytes = getIv(hashBytes, random1, random2);
|
||||
@@ -171,10 +170,10 @@ public class HarmanBinaryDataEncrypt {
|
||||
} catch (UnsupportedEncodingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
byte[] data = new byte[] {'A', 'B', 'C'};
|
||||
byte[] data = new byte[]{'A', 'B', 'C'};
|
||||
byte[] encrypted = encrypt(data);
|
||||
byte[] decrypted = decrypt(encrypted);
|
||||
if (!Arrays.equals(data, decrypted)) {
|
||||
|
||||
@@ -41,8 +41,8 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
*/
|
||||
public class HarmanSwfEncrypt {
|
||||
|
||||
private static final String GLOBAL_KEY = "Adobe AIR SDK (c) 2021 HARMAN Internation Industries Incorporated";
|
||||
|
||||
private static final String GLOBAL_KEY = "Adobe AIR SDK (c) 2021 HARMAN Internation Industries Incorporated";
|
||||
|
||||
private static int sum(byte[] data) {
|
||||
int s = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
@@ -74,13 +74,13 @@ public class HarmanSwfEncrypt {
|
||||
+ ((long) (data[start + 2] & 0xff) << 16)
|
||||
+ ((long) (data[start + 3] & 0xff) << 24);
|
||||
}
|
||||
|
||||
|
||||
private static byte[] pack(long value) {
|
||||
return new byte[]{
|
||||
(byte) (value & 0xff),
|
||||
(byte) ((value >> 8) & 0xff),
|
||||
(byte) ((value >> 16) & 0xff),
|
||||
(byte) ((value >> 24) & 0xff)
|
||||
(byte) ((value >> 24) & 0xff)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,34 +95,33 @@ public class HarmanSwfEncrypt {
|
||||
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] encrypt(byte[] data) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
|
||||
public static byte[] encrypt(byte[] data) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
return encrypt(new ByteArrayInputStream(data));
|
||||
}
|
||||
|
||||
public static byte[] encrypt(InputStream is) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
|
||||
public static byte[] encrypt(InputStream is) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] header = new byte[8];
|
||||
DataInputStream dais = new DataInputStream(is);
|
||||
dais.readFully(header);
|
||||
return encrypt(is, header);
|
||||
}
|
||||
|
||||
public static byte[] encrypt(InputStream is, byte[] header) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
public static byte[] encrypt(InputStream is, byte[] header) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
long key = getkey(header);
|
||||
|
||||
|
||||
byte[] data = readStream(is);
|
||||
|
||||
|
||||
int decryptedLength = data.length;
|
||||
long encryptedLength = decryptedLength ^ key;
|
||||
byte[] encryptedLengthBytes = pack(encryptedLength);
|
||||
|
||||
|
||||
|
||||
int paddedLength = (int) (decryptedLength + 0x1F) & ~0x1F;
|
||||
|
||||
|
||||
byte[] dataPadded = new byte[paddedLength];
|
||||
System.arraycopy(data, 0, dataPadded, 0, data.length);
|
||||
|
||||
System.arraycopy(data, 0, dataPadded, 0, data.length);
|
||||
|
||||
byte[] aesIV = new byte[16];
|
||||
System.arraycopy(header, 0, aesIV, 0, header.length); //header
|
||||
System.arraycopy(encryptedLengthBytes, 0, aesIV, 8, 4); //encrypted length
|
||||
@@ -134,23 +133,23 @@ public class HarmanSwfEncrypt {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
aesIV[i] ^= GLOBAL_KEY.charAt(i);
|
||||
}
|
||||
|
||||
byte[] aesKey = new byte[32];
|
||||
|
||||
|
||||
byte[] aesKey = new byte[32];
|
||||
|
||||
SecureRandom random = new SecureRandom();
|
||||
random.nextBytes(aesKey);
|
||||
|
||||
random.nextBytes(aesKey);
|
||||
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(aesKey, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(aesIV));
|
||||
byte[] encryptedData = cipher.doFinal(dataPadded);
|
||||
header[0] += 32; //to lowercase
|
||||
|
||||
baos.write(header);
|
||||
|
||||
baos.write(header);
|
||||
baos.write(pack(encryptedLength));
|
||||
baos.write(encryptedData, 0, paddedLength);
|
||||
|
||||
byte[] aesKeyData = new byte[32];
|
||||
|
||||
byte[] aesKeyData = new byte[32];
|
||||
for (int i = 0; i < 32; i += 4) {
|
||||
long value = unpack(aesKey, i);
|
||||
if ((i & 4) == 4) {
|
||||
@@ -163,17 +162,16 @@ public class HarmanSwfEncrypt {
|
||||
aesKeyData[i + 2] = (byte) ((value >> 16) & 0xff);
|
||||
aesKeyData[i + 3] = (byte) ((value >> 24) & 0xff);
|
||||
}
|
||||
|
||||
|
||||
baos.write(aesKeyData);
|
||||
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] decrypt(byte[] data) throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
return decrypt(new ByteArrayInputStream(data));
|
||||
}
|
||||
|
||||
|
||||
public static byte[] decrypt(InputStream is) throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
|
||||
DataInputStream dais = new DataInputStream(is);
|
||||
byte[] header = new byte[8];
|
||||
@@ -241,13 +239,13 @@ public class HarmanSwfEncrypt {
|
||||
return Arrays.copyOfRange(decryptedData, 0, decryptedLength);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
byte[] data = new byte[] {'C', 'W', 'S', 0x32, 0x01, 0x02, 0x03, 0x04, 0x41, 0x42, 0x43, 0xd, 0xa};
|
||||
public static void main(String[] args) throws Exception {
|
||||
byte[] data = new byte[]{'C', 'W', 'S', 0x32, 0x01, 0x02, 0x03, 0x04, 0x41, 0x42, 0x43, 0xd, 0xa};
|
||||
byte[] encrypted = encrypt(data);
|
||||
byte[] decrypted = decrypt(encrypted);
|
||||
|
||||
|
||||
if (!Arrays.equals(data, decrypted)) {
|
||||
throw new RuntimeException("Cannot encrypt/decrypt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user