I am creating a simple web application and want to store hashed passwords in a database. I need a hash function for an authentication token (concatenating the username and date and sending them with a hash to the client as a token).
I found that the MessageDigest Java class can help me with this. Here is one link . The basic idea is this:
public String digestString (String stringToHash) throws NoSuchAlgorithmException { MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); byte[] stringBytes = stringToHash.getBytes(); byte[] stringDigest = sha256.digest(stringBytes); return new String(stringDigest); }
I do not get: In this code, how can I set the hash key? I must be sure that the same key will be used in the verification process. How can I do this if I do not install the key?
By the way: I know that I have to add salt (256 bytes in this case) to the hashed text before hashing it.
source share