Currently I'm trying to generate Secure passwords, and I have the next method:
public String blowfishEncrypt(String pass){
//String encPass = BCrypt.hashpw(pass, BCrypt.gensalt(12));
//return encPass;
try{
//KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");
String key = "q2eRE#$%FwdfsdfCS#$@wDwfV3evf$&%";
byte[] keyData = key.getBytes();
SecretKeySpec KS = new SecretKeySpec(keyData, "Blowfish");
//SecretKey secretkey = keygenerator.generateKey();
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, KS);
byte[] encrypted = cipher.doFinal(pass.getBytes());
return encrypted+"";
}catch(Exception e){
e.printStackTrace();
return "error";
}
}
It's generating diferent Strings each time I access to the method, even when I'm using a static key and I introduce the same word.
I also think it isn't sure to use an explicit key (added manually in the code).
My idea is to encrypt the text introduced and add it to the database (encrypted), and then, if the user tries to Login, The introduced text will be encrypted and compared with the one that is encripted in the database.
The problem is that my method is generating different strings with the same word, so passwords will never match.
- input = qwerty ->output -> [B@327b2e35
- input = qwerty ->output -> [B@1b045c1
Maybe I'm doing something wrong, I'd like to know it
Thanks for your answers