· 4 years ago · Oct 26, 2020, 10:38 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 javax.crypto.spec.IvParameterSpec;
8import java.util.Base64;
9
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 = 16 * 8;
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 = Base64.getDecoder().decode(base64EncryptedData);
31 byte[] utf8 = dcipher.doFinal(decryptedData);
32 return new String(utf8, "UTF8");
33 }
34
35 public static void main(String args[]) throws Exception {
36 String encrypted = Base64.getEncoder().encodeToString(Base64.getUrlDecoder().decode(("cWKz2Ajf8LPntPBqGdwIZT-3TxXKw40wCahYJRPGKzWzz2mHacBCTnoy43LOc1bZ0OoaVK734Azc_LsQd--Hl_VI_tCjF4-67-7-frheoK5m5ViaShI9n--nfAex2Jin").getBytes()));
37 String decrypted;
38 for (int i = 0; i <= 9999; i++) {
39 String code = String.valueOf(i);
40 try {
41 decrypted = new Decrypter(code).decrypt(encrypted);
42 System.out.println(decrypted);
43 } catch(javax.crypto.BadPaddingException j) {
44 }
45 }
46 }
47}