The ECMAScript code shown here SHA-256 hashes a string (sample output shown below).

hash: e52a26fe5ef07876b5e7f57c907a5a033cb60fc6eb9ffc462748b9c9aeeb45f5

importPackage(java.io);
importPackage(Packages.java.lang);
importClass(java.security.MessageDigest);
importClass(java.nio.charset.StandardCharsets);
importClass(java.lang.StringBuffer);

var varMyString = "Hash this string please!";

var varDigest = MessageDigest.getInstance("SHA-256");

var varOriginalString = new java.lang.String(varMyString);
var varHashedString = varDigest.digest(varOriginalString.getBytes(StandardCharsets.UTF_8));

var varFinalString = new StringBuffer();
for (i = 0; i < varHashedString.length; i++)
{
    varFinalString.append(Integer.toString((varHashedString[i] & 0xff) + 0x100, 16).substring(1));
}

print ("hash: " + varFinalString);