@Test public void testEncodePassword() throws NoSuchAlgorithmException { final String algorithm = "SHA-256"; final String password = "password"; final String hash = new MessageDigestPasswordEncoder(algorithm).encodePassword(password); final String expectedHash = "{SHA-256}c33d66fe65ffcca1f2260e6982dbf0c614b6ea3ddfdb37d6142fbec0feca5245"; assertEquals("encodePassword", expectedHash, hash); }
public String encodePassword(String password) throws NoSuchAlgorithmException { final MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(password.getBytes(UTF8_CHARSET)); messageDigest.update(SALT); final byte[] digest = messageDigest.digest(); return "{" + algorithm + '}' + hexa(digest); }
MessageDigestPasswordEncoder { public String encodePassword(String password) throws NoSuchAlgorithmException { final MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(password.getBytes(UTF8_CHARSET)); messageDigest.update(SALT); final byte[] digest = messageDigest.digest(); return "{" + algorithm + '}' + hexa(digest); } }
MessageDigestPasswordEncoder { public String encodePassword(String password) throws NoSuchAlgorithmException { final MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(password.getBytes(UTF8_CHARSET)); messageDigest.update(SALT); final byte[] digest = messageDigest.digest(); return "{" + algorithm + '}' + hexa(digest); } MessageDigestPasswordEncoder(String algorithm); }
MessageDigestPasswordEncoder { public String encodePassword(String password) throws NoSuchAlgorithmException { final MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(password.getBytes(UTF8_CHARSET)); messageDigest.update(SALT); final byte[] digest = messageDigest.digest(); return "{" + algorithm + '}' + hexa(digest); } MessageDigestPasswordEncoder(String algorithm); static void main(String[] args); String encodePassword(String password); }
MessageDigestPasswordEncoder { public String encodePassword(String password) throws NoSuchAlgorithmException { final MessageDigest messageDigest = MessageDigest.getInstance(algorithm); messageDigest.update(password.getBytes(UTF8_CHARSET)); messageDigest.update(SALT); final byte[] digest = messageDigest.digest(); return "{" + algorithm + '}' + hexa(digest); } MessageDigestPasswordEncoder(String algorithm); static void main(String[] args); String encodePassword(String password);  }