I use solution from here:
public static byte[] getEncryptedPassword(String password, byte[] salt, int iterations, int derivedKeyLength) throws NoSuchAlgorithmException, InvalidKeySpecException {
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, derivedKeyLength * 8);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
return f.generateSecret(spec).getEncoded();
}
The problem is that when I do:
System.out.println(new String(getEncryptedPassword(p,s,i,l)));
I get a very strange string, something like ���:
, but I want a normal string which I can save in DB. What is my mistake?