1import org.apache.commons.codec.digest.DigestUtils;
2
3String password = "123456";
4String result = DigestUtils.sha256Hex(password);
1String password = "123456";
2
3MessageDigest md = MessageDigest.getInstance("SHA-256");
4byte[]hashInBytes = md.digest(password.getBytes(StandardCharsets.UTF__8));
5
6//bytes to hex
7StringBuilder sb = new StringBuilder();
8for (byte b : hashInBytes) {
9 sb.append(String.format("%02x", b));
10}
11System.out.println(sb.toString());