SonyUnXml.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package QuickVerifyCrap;
  2. import javax.crypto.BadPaddingException;
  3. import javax.crypto.Cipher;
  4. import javax.crypto.IllegalBlockSizeException;
  5. import javax.crypto.NoSuchPaddingException;
  6. import javax.crypto.spec.SecretKeySpec;
  7. import java.io.*;
  8. import java.security.InvalidKeyException;
  9. import java.security.MessageDigest;
  10. import java.security.NoSuchAlgorithmException;
  11. import java.security.Security;
  12. import java.util.Locale;
  13. import org.bouncycastle.jce.provider.BouncyCastleProvider;
  14. public class SonyUnXml {
  15. public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IOException, IllegalBlockSizeException, BadPaddingException {
  16. Security.addProvider(new BouncyCastleProvider());
  17. byte[] c = new byte[] {
  18. 79, -94, 121, -103, -1, -48, -117, 31, -28, -46,
  19. 96, -43, 123, 109, 60, 23 };
  20. SecretKeySpec secretKeySpec = new SecretKeySpec(c, "AES");
  21. Cipher cipher = Cipher.getInstance("AES/ECB/ZeroBytePadding");
  22. cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
  23. File f = new File("/home/tgoerner/Downloads/sony-FWH/info3/info.xml");
  24. RandomAccessFile f2 = new RandomAccessFile(f,"r");
  25. //f2.seek(0x4A);
  26. int fl = (int)f.length();
  27. byte[] file = new byte[fl];
  28. int read = f2.read(file);
  29. System.out.println(bytesToHex(MessageDigest.getInstance("SHA-1").digest(file)));
  30. if(read<fl)
  31. {
  32. System.err.println("ZARF");
  33. }
  34. byte[] out = cipher.doFinal(file);
  35. System.out.println(bytesToHex(MessageDigest.getInstance("SHA-1").digest(out)));
  36. FileOutputStream os = new FileOutputStream(new File("/home/tgoerner/Downloads/sony-FWH/info3/info.xml.dec"));
  37. os.write(out);
  38. }
  39. public static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
  40. public static String bytesToHex(byte[] bytes) {
  41. char[] hexChars = new char[bytes.length * 2];
  42. for (int j = 0; j < bytes.length; j++) {
  43. int v = bytes[j] & 0xFF;
  44. hexChars[j * 2] = HEX_ARRAY[v >>> 4];
  45. hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
  46. }
  47. String hexxit = new String(hexChars).toLowerCase(Locale.ROOT);
  48. //hexxit = hexxit.replaceAll("^0+", "");
  49. return hexxit;
  50. }
  51. }