· 8 years ago · Jan 25, 2018, 04:40 PM
1import java.io.*;
2import java.util.Random;
3import javax.crypto.*;
4import javax.crypto.spec.*;
5
6public class MinecraftPasswordRetrieval {
7 public static final String ENCRYPTION_TYPE = "PBEWithMD5AndDES";
8 public static final int ENCRYPTION_ITERATIONS = 5;
9 public static final String ENCRYPTION_KEY = "passwordfile";
10 public static final long SALT_SEED = 43287234L;
11 public static final int SALT_LENGTH = 8;
12
13 public static final int WINDOWS = 0;
14 public static final int MACOSX = 1;
15 public static final int LINUX = 2;
16
17 public static void main(String[] args) throws Exception {
18 File passFile = new File(getMinecraftDir(), "lastlogin");
19 DataInputStream dis = new DataInputStream(new CipherInputStream(new FileInputStream(passFile), getCipher()));
20 System.out.println("Username: " + dis.readUTF());
21 System.out.println("Password: " + dis.readUTF());
22 dis.close();
23 }
24
25 public static File getMinecraftDir() {
26 File home = new File(System.getProperty("user.home"));
27 switch (getOS()) {
28 case WINDOWS: return new File(System.getenv("APPDATA"), ".minecraft");
29 case MACOSX: return new File(home, "Library/Application Support/minecraft");
30 case LINUX: return new File(home, ".minecraft");
31 }
32 throw new RuntimeException("The Compiler is too stupid to realize that this line is dead code.");
33 }
34
35 public static Cipher getCipher() throws Exception {
36 SecretKey pbeKey = SecretKeyFactory.getInstance(ENCRYPTION_TYPE).generateSecret(new PBEKeySpec(ENCRYPTION_KEY.toCharArray()));
37 PBEParameterSpec pbeParamSpec = new PBEParameterSpec(getSalt(), ENCRYPTION_ITERATIONS);
38 Cipher cipher = Cipher.getInstance(ENCRYPTION_TYPE);
39 cipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
40 return cipher;
41 }
42
43 public static byte[] getSalt() {
44 Random random = new Random(SALT_SEED);
45 byte[] salt = new byte[SALT_LENGTH];
46 random.nextBytes(salt);
47 return salt;
48 }
49
50 public static int getOS() {
51 String osName = System.getProperty("os.name");
52 if (osName.startsWith("Windows"))
53 return WINDOWS;
54 else if (osName.equals("Mac OS X"))
55 return MACOSX;
56 return LINUX; // Linux, BSD, Solaris, …
57 }
58}