Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Random;
- import javax.crypto.*;
- import javax.crypto.spec.*;
- public class MinecraftPasswordRetrieval {
- public static final String ENCRYPTION_TYPE = "PBEWithMD5AndDES";
- public static final int ENCRYPTION_ITERATIONS = 5;
- public static final String ENCRYPTION_KEY = "passwordfile";
- public static final long SALT_SEED = 43287234L;
- public static final int SALT_LENGTH = 8;
- public static final int WINDOWS = 0;
- public static final int MACOSX = 1;
- public static final int LINUX = 2;
- public static void main(String[] args) throws Exception {
- File passFile = new File(getMinecraftDir(), "lastlogin");
- DataInputStream dis = new DataInputStream(new CipherInputStream(new FileInputStream(passFile), getCipher()));
- System.out.println("Username: " + dis.readUTF());
- System.out.println("Password: " + dis.readUTF());
- dis.close();
- }
- public static File getMinecraftDir() {
- File home = new File(System.getProperty("user.home"));
- switch (getOS()) {
- case WINDOWS: return new File(System.getenv("APPDATA"), ".minecraft");
- case MACOSX: return new File(home, "Library/Application Support/minecraft");
- case LINUX: return new File(home, ".minecraft");
- }
- throw new RuntimeException("The Compiler is too stupid to realize that this line is dead code.");
- }
- public static Cipher getCipher() throws Exception {
- SecretKey pbeKey = SecretKeyFactory.getInstance(ENCRYPTION_TYPE).generateSecret(new PBEKeySpec(ENCRYPTION_KEY.toCharArray()));
- PBEParameterSpec pbeParamSpec = new PBEParameterSpec(getSalt(), ENCRYPTION_ITERATIONS);
- Cipher cipher = Cipher.getInstance(ENCRYPTION_TYPE);
- cipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
- return cipher;
- }
- public static byte[] getSalt() {
- Random random = new Random(SALT_SEED);
- byte[] salt = new byte[SALT_LENGTH];
- random.nextBytes(salt);
- return salt;
- }
- public static int getOS() {
- String osName = System.getProperty("os.name");
- if (osName.startsWith("Windows"))
- return WINDOWS;
- else if (osName.equals("Mac OS X"))
- return MACOSX;
- return LINUX; // Linux, BSD, Solaris, …
- }
- }
Add Comment
Please, Sign In to add comment