Guest User

MinecraftPasswordRetrieval.java

a guest
Oct 19th, 2011
4,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Random;
  3. import javax.crypto.*;
  4. import javax.crypto.spec.*;
  5.  
  6. public 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 void main(String[] args) throws Exception {
  14.         File passFile = new File(getMinecraftDir(), "lastlogin");
  15.         DataInputStream dis = new DataInputStream(new CipherInputStream(new FileInputStream(passFile), getCipher()));
  16.         System.out.println("Username: " + dis.readUTF());
  17.         System.out.println("Password: " + dis.readUTF());
  18.         dis.close();
  19.     }
  20.    
  21.     public static File getMinecraftDir() {
  22.         File home = new File(System.getProperty("user.home"));
  23.         switch (OS.getOS()) {
  24.             case WINDOWS: return new File(System.getenv("APPDATA"), ".minecraft");
  25.             case MACOSX:  return new File(home, "Library/Application Support/minecraft");
  26.             case LINUX:   return new File(home, ".minecraft");
  27.         }
  28.         throw new RuntimeException("The Compiler is too stupid to realize that this line is dead code.");
  29.     }
  30.    
  31.     public static Cipher getCipher() throws Exception {
  32.         SecretKey pbeKey = SecretKeyFactory.getInstance(ENCRYPTION_TYPE).generateSecret(new PBEKeySpec(ENCRYPTION_KEY.toCharArray()));
  33.         PBEParameterSpec pbeParamSpec = new PBEParameterSpec(getSalt(), ENCRYPTION_ITERATIONS);
  34.         Cipher cipher = Cipher.getInstance(ENCRYPTION_TYPE);
  35.         cipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
  36.         return cipher;
  37.     }
  38.    
  39.     public static byte[] getSalt() {
  40.         Random random = new Random(SALT_SEED);
  41.         byte[] salt = new byte[SALT_LENGTH];
  42.         random.nextBytes(salt);
  43.         return salt;
  44.     }
  45.    
  46.     public static enum OS { // http://java.net/projects/swingx/sources/svn/content/trunk/swingx-core/src/main/java/org/jdesktop/swingx/util/Utilities.java
  47.         WINDOWS, LINUX, MACOSX;
  48.         public static OS getOS() {
  49.             String osName = System.getProperty("os.name");
  50.             if (osName.startsWith("Windows"))
  51.                 return WINDOWS;
  52.             else if (osName.equals("Mac OS X"))
  53.                 return MACOSX;
  54.             return LINUX; // Linux, BSD, Solaris, …
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment