· 7 years ago · Oct 11, 2018, 12:04 PM
1package ch.dola.minecraft.lastlogin;
2
3import java.io.DataInputStream;
4import java.io.FileInputStream;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.io.PrintStream;
8import java.security.InvalidAlgorithmParameterException;
9import java.security.InvalidKeyException;
10import java.security.NoSuchAlgorithmException;
11import java.security.spec.InvalidKeySpecException;
12import java.util.Random;
13
14import javax.crypto.Cipher;
15import javax.crypto.CipherInputStream;
16import javax.crypto.NoSuchPaddingException;
17import javax.crypto.SecretKey;
18import javax.crypto.SecretKeyFactory;
19import javax.crypto.spec.PBEKeySpec;
20import javax.crypto.spec.PBEParameterSpec;
21
22public class Main {
23
24 /**
25 * Decrypts the username and password from the minecraft lastlogin file, which contains the last saved login informations.
26 *
27 * @param args[0] The path to the lastlogin file in the minecraft directory
28 */
29 public static void main(String[] args) {
30
31 PrintStream out = System.out;
32 PrintStream error = System.err;
33
34 out.println("Starting Minecraft lastlogin decryptor");
35 out.println("--------------------------------------");
36 out.println();
37 if(args.length >= 1){
38 out.println("Inspecting file at " + args[0]);
39 LastLoginDecryptor lld;
40 try {
41 lld = new LastLoginDecryptor(args[0]);
42 out.println("Trying to decrypt data...");
43 out.println();
44 out.println("Username extraced: " + lld.getUsername());
45 out.println("Password extraced: " + lld.getPassword());
46 } catch (FileNotFoundException e) {
47 error.println("Error: Specified File was not found.");
48 } catch (IOException e) {
49 error.println("Error: Could not read from specified file. Maybe permission is missing.");
50 } catch (Exception e) {
51 error.println("Error: An unknown error occured: ");
52 e.printStackTrace();
53 }
54
55 } else{
56 out.println("Usage:");
57 out.println("java -jar lastlogindecryptor.jar FILENAME");
58 out.println("or make your own executable .sh file including the following line:");
59 out.println("java -jar lastlogindecryptor.jar $1");
60 }
61 }
62
63 static class LastLoginDecryptor {
64
65 String password = null;
66 String username = null;
67
68 boolean decrypted = false;
69
70 DataInputStream in;
71
72 public LastLoginDecryptor(String filePath) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, InvalidKeyException, InvalidAlgorithmParameterException, FileNotFoundException{
73 Random random = new Random(43287234L);
74 byte[] salt = new byte[8];
75 random.nextBytes(salt);
76 PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
77 SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec("passwordfile".toCharArray()));
78 Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
79 cipher.init(2, pbeKey, pbeParamSpec);
80
81 in = new DataInputStream(new CipherInputStream(new FileInputStream(filePath), cipher));
82 }
83
84 private void decrypt() throws IOException{
85 username = in.readUTF();
86 password = in.readUTF();
87 in.close();
88
89 decrypted = true;
90 }
91
92 public String getPassword() throws IOException{
93 if (!decrypted){
94 decrypt();
95 }
96 return password;
97 }
98
99 public String getUsername() throws IOException{
100 if (!decrypted){
101 decrypt();
102 }
103 return username;
104 }
105 }
106}