I have a utility class with a method responsible for encrypting the user password. This is the method:
public static String encryptPassword(String password) {
MessageDigest md = null;
try {
md = getInstance("sha-512");
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(PasswordUtils.class.getName()).log(Level.SEVERE, null, ex);
throw new IllegalArgumentException();
}
md.update(password.getBytes());
return Base64.getEncoder().encodeToString(md.digest());
}
I'm using MySQL
to persist my data and I want to persist the password as a VARCHAR
. To get an idea of the needed length I made some research and found this post and this one who talk about a needed length of 128. I tested the method manually with severals strings and the String.length()
method of the hashed strings gives me a fixed length of 88. Also I saw an example project and uses 'VARCHAR(100)' to store the password.
What is the optimal size of the VARCHAR
for this algorithm? Thanks in advance for your answers.