/** * Hashes a char array using the algorithm parametrised in the instance. * * @param newPassword * the new password to hash. * @return the password digest. * @throws NoSuchAlgorithmException * when the digest algorithm is not supported. * @throws IOException * whenever an I/O exception occurs. */ protected String digestAndEncode(char... newPassword) throws NoSuchAlgorithmException, IOException { if (getDigestAlgorithm() != null) { MessageDigest md = MessageDigest.getInstance(getDigestAlgorithm()); md.reset(); md.update(new String(newPassword).getBytes(StandardCharsets.UTF_8.name())); byte[] digest = md.digest(); return getPasswordStorePrefix() + encode(digest); } return new String(newPassword); }