Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import javax.crypto.*;
- import java.util.*;
- import javax.crypto.spec.*;
- public class test
- {
- public static void main( String[] args )
- {
- new test();
- }
- public String user = "";
- public String pass = "";
- public test()
- {
- readUsername();
- System.out.println( user + " " + pass );
- }
- private void readUsername()
- {
- try
- {
- File lastLogin = new File( "./lastlogin" );
- Cipher cipher = getCipher( 2, "passwordfile" );
- DataInputStream dis;
- if ( cipher != null )
- dis = new DataInputStream( new CipherInputStream( new FileInputStream(lastLogin), cipher ) );
- else
- {
- dis = new DataInputStream( new FileInputStream( lastLogin ) );
- }
- user = dis.readUTF();
- pass = dis.readUTF();
- dis.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- private Cipher getCipher(int mode, String password) throws Exception
- {
- 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(password.toCharArray()));
- Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
- cipher.init(mode, pbeKey, pbeParamSpec);
- return cipher;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement