I am trying an example:
String hashAlgorithm ="sha-256"
...
md=MessageDigest.getInstance(hashAlgorithm);
byte[] enteredPasswordDigest = md.digest(policy.getPassword().getBytes());
if (!MessageDigest.isEqual(enteredPasswordDigest, realPassword.getBytes())) {
...
}
However, the hashed password is stored as a string in the database. When I do that comparison, it fails. When I debug it, enteredPasswordDigest has 32 byte length and realPassword.getBytes() has 64 byte length.
What did I miss?
I solved my question with that point: Hashed password as a string at database is “hex”. That is the main point. So I got the hex of entered password’s byte array digest. Then I compared strings that has hex values.