Skip to content

Instantly share code, notes, and snippets.

@dola
Created May 19, 2012 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dola/2732106 to your computer and use it in GitHub Desktop.
Save dola/2732106 to your computer and use it in GitHub Desktop.
Minecraft lastlogin decryptor
package ch.dola.minecraft.lastlogin;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
public class Main {
/**
* Decrypts the username and password from the minecraft lastlogin file, which contains the last saved login informations.
*
* @param args[0] The path to the lastlogin file in the minecraft directory
*/
public static void main(String[] args) {
PrintStream out = System.out;
PrintStream error = System.err;
out.println("Starting Minecraft lastlogin decryptor");
out.println("--------------------------------------");
out.println();
if(args.length >= 1){
out.println("Inspecting file at " + args[0]);
LastLoginDecryptor lld;
try {
lld = new LastLoginDecryptor(args[0]);
out.println("Trying to decrypt data...");
out.println();
out.println("Username extraced: " + lld.getUsername());
out.println("Password extraced: " + lld.getPassword());
} catch (FileNotFoundException e) {
error.println("Error: Specified File was not found.");
} catch (IOException e) {
error.println("Error: Could not read from specified file. Maybe permission is missing.");
} catch (Exception e) {
error.println("Error: An unknown error occured: ");
e.printStackTrace();
}
} else{
out.println("Usage:");
out.println("java -jar lastlogindecryptor.jar FILENAME");
out.println("or make your own executable .sh file including the following line:");
out.println("java -jar lastlogindecryptor.jar $1");
}
}
static class LastLoginDecryptor {
String password = null;
String username = null;
boolean decrypted = false;
DataInputStream in;
public LastLoginDecryptor(String filePath) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, InvalidKeyException, InvalidAlgorithmParameterException, FileNotFoundException{
Random random = new Random(43287234L);
byte[] salt = new byte[8];
random.nextBytes(salt);
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec("passwordfile".toCharArray()));
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(2, pbeKey, pbeParamSpec);
in = new DataInputStream(new CipherInputStream(new FileInputStream(filePath), cipher));
}
private void decrypt() throws IOException{
username = in.readUTF();
password = in.readUTF();
in.close();
decrypted = true;
}
public String getPassword() throws IOException{
if (!decrypted){
decrypt();
}
return password;
}
public String getUsername() throws IOException{
if (!decrypted){
decrypt();
}
return username;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment