Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.io.*;
  2. import javax.crypto.*;
  3. import java.util.*;
  4. import javax.crypto.spec.*;
  5.  
  6. public class test
  7. {
  8.     public static void main( String[] args )
  9.     {
  10.         new test();
  11.     }
  12.    
  13.     public String user = "";
  14.     public String pass = "";
  15.  
  16.     public test()
  17.     {
  18.         readUsername();
  19.         System.out.println( user + " " + pass );
  20.     }
  21.  
  22.  
  23.     private void readUsername()
  24.     {
  25.         try
  26.         {
  27.             File lastLogin = new File( "./lastlogin" );
  28.             Cipher cipher = getCipher( 2, "passwordfile" );
  29.             DataInputStream dis;
  30.             if ( cipher != null )
  31.                 dis = new DataInputStream( new CipherInputStream( new FileInputStream(lastLogin), cipher ) );
  32.             else
  33.             {
  34.                 dis = new DataInputStream( new FileInputStream( lastLogin ) );
  35.             }
  36.             user = dis.readUTF();
  37.             pass = dis.readUTF();
  38.             dis.close();
  39.         }
  40.         catch (Exception e)
  41.         {
  42.           e.printStackTrace();
  43.         }
  44.     }
  45.  
  46.     private Cipher getCipher(int mode, String password) throws Exception
  47.     {
  48.         Random random = new Random(43287234L);
  49.         byte[] salt = new byte[8];
  50.         random.nextBytes(salt);
  51.         PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
  52.  
  53.         SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
  54.         Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
  55.         cipher.init(mode, pbeKey, pbeParamSpec);
  56.         return cipher;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement