/** * Creates a hash for a clear text password. * * @param rawPassword The password to hash. The password may also (optionally) be prefixed * by <em>salt</em> that should be used for computing the hash value. * If given, the salt needs to be provided in the form of the Base64 encoding * of the salt bytes wrapped in curly braces: * <em>{Base64(salt)}password</em>. * @return The Base64 encoding of the bytes resulting from applying the hash function to * the byte array consisting of the salt bytes (if a salt is used) and the UTF-8 * encoding of the clear text password. */ @Override public String encode(final CharSequence rawPassword) { // parse given string into (optional) salt and password final ClearTextPassword password = new ClearTextPassword(rawPassword.toString()); return Base64.getEncoder().encodeToString(digest(password.salt, password.password)); }