Kod:
import java****.*;
import javax.crypto.*;
import java.util.*;
import javax.crypto.spec.*;
public class test
{
public static **** main(String[] args)
{
new test();
}
public String user = "";
public String pass = "";
public test()
{
readUsername();
System.out.println(user+" "+pass);
}
private **** readUsername() {
try {
//File lastLogin = new File(Util.getWorkingDirectory(), "lastlogin");
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;
}
}