· 9 years ago · Dec 05, 2016, 12:06 PM
1private static void doAES() throws Exception {
2 //String ct = "Jg7QI1RrVRYNjREM2+KUnifcnQgFhv0gGQ41yquM1+0HAPdK+s/FfUAo";
3 String ct = "bB0jXIKsr4F5Ir8LtvM8sWTBF5KHsn5zBkA3yW9zgg==";
4 //String initVector = "b2Y+/uy/M6dtShDAGQaYzg==";
5 String initVector = "jm/QEdqKgJ5WbE8gia9sjA==";
6
7 //byte[] keyBytes = {-127, -82, -63, 75, 37, -34, 0, 0, -60, 94, 42, 101, 16, -65, 100, 101};
8 byte[] keyBytes = {-80, -9, 83, 31, 0, 0, 61, -41, -33, 39, 46, 20, -48, -92, -44, 51};
9
10 BASE64Decoder decoder = new BASE64Decoder();
11
12 byte[] ctBytes = decoder.decodeBuffer(ct);
13 byte[] initVectorBytes = decoder.decodeBuffer(initVector);
14 AlgorithmParameterSpec iv = new IvParameterSpec(initVectorBytes);
15
16 Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
17 for (int i = -128; i < 128; i++) {
18 for (int j = -128; j < 128; j++) {
19 //keyBytes[6] = (byte) i;
20 //keyBytes[7] = (byte) j;
21 keyBytes[4] = (byte) i;
22 keyBytes[5] = (byte) j;
23
24 SecretKey secretKey = new SecretKeySpec(keyBytes, "AES");
25 cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
26
27 byte[] openTextBytes = cipher.doFinal(ctBytes);
28 String openText = new String(openTextBytes);
29 long count = openText.chars().filter(Character::isLetter).count();
30 if (count > openText.length() / 1.5) {
31 System.out.println(openText);
32 System.out.println("\t" + i + " " + j);
33 }
34 }
35 }
36 }