Guest User

Untitled

a guest
Oct 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. package ch.dola.minecraft.lastlogin;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.PrintStream;
  8. import java.security.InvalidAlgorithmParameterException;
  9. import java.security.InvalidKeyException;
  10. import java.security.NoSuchAlgorithmException;
  11. import java.security.spec.InvalidKeySpecException;
  12. import java.util.Random;
  13.  
  14. import javax.crypto.Cipher;
  15. import javax.crypto.CipherInputStream;
  16. import javax.crypto.NoSuchPaddingException;
  17. import javax.crypto.SecretKey;
  18. import javax.crypto.SecretKeyFactory;
  19. import javax.crypto.spec.PBEKeySpec;
  20. import javax.crypto.spec.PBEParameterSpec;
  21.  
  22. public 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. }
Add Comment
Please, Sign In to add comment