En la clase Blowfish, genero una contraseña:
Cita: public class blowfish
{
private static String pass= "pruebapass";
public static void main(String[] args) throws Exception {
KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");
SecretKey secretkey = keygenerator.generateKey();
Cipher cipher = Cipher.getInstance("Blowfish");
//ENCRIPTAR PASS
cipher.init(Cipher.ENCRYPT_MODE, secretkey);
byte[] encriptarPASS = cipher.doFinal(pass.getBytes());
try{
FileWriter fw = new FileWriter(new File("/home/carlos/Escritorio/password.txt"));
PrintWriter pw = new PrintWriter(fw);
pw.println(encriptarUSER);
pw.close();
}
catch(IOException ex)
{
System.out.println("error");
}
Luego cierro programa y abro otro programa. Estamos en la clase VentanaLogin y leo:
Cita: if (result == JFileChooser.APPROVE_OPTION){
byte [] aux;
String linea=null;
File file = fileChooser.getSelectedFile();
/***LECTURA DEL FICHERO ***/
try{
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
linea = br.readLine();
while(linea!=null)
{
KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");
SecretKey secretkey = keygenerator.generateKey();
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, secretkey);
aux=linea.getBytes();
byte [] usuario = cipher.doFinal(aux);
JOptionPane.showMessageDialog(null, new String(usuario));
//bf.DESEncriptar_Usuario(aux);
linea=br.readLine();
}
br.close();
}
catch(IOException ex)
{
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}