Programming Tips - Java: make a SHA-256 hash (digest)

Date: 2022oct12 Language: Java Q. Java: make a SHA-256 hash (digest) A.
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public static String makeSha256(final String thingOne, final String thingTwo) { MessageDigest md; try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException ex) { // Every implementation of the Java platform is required to support // the following standard MessageDigest algorithms: MD5 SHA-1 SHA-256 return ""; } md.update(thingOne.getBytes()); md.update(thingTwo.getBytes()); final byte byteData[] = md.digest(); return Hex.toHexString(byteData); // This function is available elsewhere on davekb }