· 4 years ago · Oct 26, 2020, 08:42 PM
1import javax.crypto.Cipher;
2import java.security.spec.KeySpec;
3import javax.crypto.spec.PBEKeySpec;
4import javax.crypto.SecretKey;
5import javax.crypto.spec.SecretKeySpec;
6import javax.crypto.SecretKeyFactory;
7import java.security.AlgorithmParameters;
8import javax.crypto.spec.IvParameterSpec;
9import java.util.Base64;
10
11public class Decrypter {
12 Cipher dcipher;
13
14 byte[] salt = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
15 int iterationCount = 1024;
16 int keyStrength = 128;
17 SecretKey key;
18 byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
19
20 Decrypter(String passPhrase) throws Exception {
21 SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
22 KeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount, keyStrength);
23 SecretKey tmp = factory.generateSecret(spec);
24 key = new SecretKeySpec(tmp.getEncoded(), "AES");
25 dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
26 }
27
28 public String decrypt(String base64EncryptedData) throws Exception {
29 dcipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
30 byte[] decryptedData = new sun.misc.BASE64Decoder().decodeBuffer(base64EncryptedData);
31 byte[] utf8 = dcipher.doFinal(decryptedData);
32 return new String(utf8, "UTF8");
33 }
34
35 public static String decryptWithNum(int num, String tocken) throws Exception {
36 Decrypter decrypter = new Decrypter(Integer.toString(num));
37 String decrypted;
38 try {
39 decrypted = decrypter.decrypt(tocken);
40 return decrypted;
41 } catch(javax.crypto.BadPaddingException _) {
42 return "";
43 }
44 }
45
46 public static String encode(String raw) {
47 return Base64.getEncoder().encodeToString(Base64.getUrlDecoder().decode(raw.getBytes()));
48 }
49
50 public static void main(String args[]) throws Exception {
51 String encrypted = Decrypter.encode("cWKz2Ajf8LPntPBqGdwIZT-3TxXKw40wCahYJRPGKzWzz2mHacBCTnoy43LOc1bZ0OoaVK734Azc_LsQd--Hl_VI_tCjF4-67-7-frheoK5m5ViaShI9n--nfAex2Jin");
52 for (int i = 0; i < 100000; i++) {
53 String res = Decrypter.decryptWithNum(i, encrypted);
54 for (int j = 0; j < res.length(); ++j) {
55 if ((int)res.charAt(j) > 128) {
56 res = "";
57 break;
58 }
59 }
60 if (res != "") {
61 System.out.println(res);
62 }
63 }
64 }
65}
66