I am using the Spring Roo framework which uses Spring Security as security framework. I configured it the following way:
Finally I came up with this solution, thank to @Oleg Estekhin comment:
public String sha256(String original) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(original.getBytes());
byte[] digest = md.digest();
return new String(Hex.encodeHexString(digest));
}