· 6 years ago · Apr 01, 2019, 01:26 AM
1import java.util.Base64;
2import javax.crypto.Cipher;
3import javax.crypto.NoSuchPaddingException;
4import javax.crypto.SecretKey;
5import javax.crypto.SecretKeyFactory;
6import javax.crypto.spec.DESKeySpec;
7
8public class loader {
9
10 /*
11 * PROGRAM START
12 */
13 public static void main(String[] args) throws Exception {
14 /* Set our encoded object and key here for ease of use */
15 String character_set = "ISO-8859-1";
16 String encoded_key = "SnNGOTg3Ni0=";
17 String encoded_object = "wHo0wmLu5ceItIi+I7XkEi1GAb4h12WZ894pA+Z4OH7bco2jXEy1Rd1x5LURafml70KtDtngjDm0mNzA9qHjYerxo0jW7zu1Qxb78J8MRRgV/oWNsOb5owxiays=";
18
19 /* Convert the key to the correct charset */
20 byte[] converted_key = encoded_key.getBytes();
21 byte[] converted_object = encoded_object.getBytes();
22
23 /* Load our captured objects from command line, decode */
24 byte[] decoded_key = Base64.getDecoder().decode(converted_key);
25 byte[] decoded_object = Base64.getDecoder().decode(converted_object);
26
27 String decoded_string = new String(decoded_object);
28 System.out.println(decoded_object.length);
29
30 /*
31 * DO WE NEED TO PUT DCIPHER IN BASE64 mode?
32 */
33
34 /* Set up our secret key */
35 DESKeySpec dks = new DESKeySpec(decoded_key);
36 SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
37 SecretKey desKey = skf.generateSecret(dks);
38
39 /* Set up our cipher (DES / ECB / PKCS5Padding)*/
40 Cipher dcipher = Cipher.getInstance("DES");
41 dcipher.init(Cipher.DECRYPT_MODE, desKey);
42
43 /* Decrypt and convert to string via charset */
44 byte[] decrypted_object = dcipher.doFinal(decoded_object);
45 String string_object = new String(decrypted_object, character_set);
46
47 /* Debug */
48 System.out.println(string_object);
49 // System.out.println(decoded_key);
50 // System.out.println(decoded_object);
51 }
52}